SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    404 error - rewrite

    Hi Chaps, is there anything i can do to check if records exist on a landing page after a rewrite...for example

    website.com/events/real_event_title

    website.com/events/this_title_doesnt_exist_but_ill_show_the_page_anyway

    both arrive using:

    rewriteRule ^events/([A-Z0-9_:,']+)$ landingpage.php?title=$1 [NC,L]

    .so if i delete one of the events and a site links to the event they wont be redirected to the home page

    Thanks in advance

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    That rewrite should redirect anything in that format, so they should both arrive at landingpage.php.

    It would then be up to landingpage.php to know what to do with it from there. The rewrite has no clue what is and isn't valid.

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    barney,

    Sam's got the correct answer - unless you want to precede that with a RewriteCond to avoid sending existing files there, too (or other things that a RewriteCond can do). For what you've asked, though, via your code, landingpage.php must have the "intelligence" to provide a 404 response when required (I use the Home Page for Wilderness Wally's website: http://wilderness-wally.com where I do that same thing, i.e., using article titles to redirect to the handler file to fetch the article requested ... or the Welcome page when the request was invalid).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks both..i just thought that might be some kind of htaccess controls for checking (wishful thinking)

    so.... how do you check the value and redirect if the record doesnt exist ( this was my indirect question in the first post really )?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    barney,

    I've got to throw your question back at you: How do you select the content for a page which is generated by your script (using website.com/events/real_event_title)? Did you bother to look at the link I provided (where I do exactly that)? Did you "play" with a link from WW's TOC so that you were requesting a page which was not available? If so, didn't you get served the Home (Welcome) Page? That's simply in the MySQL code which attempts to fetch the contents by the title. If the title's not found, zero records are returned so that requires another visit to the db to fetch the Welcome page contents.

    Since mod_rewrite is not clairvoyant, it can't guess at the titles in your db so you've actually got to handle that in your "handler" file. Big surprise, eh?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh yeah DK, ..i had a play with your link, popup and return to home page...

    So, if query is empty then redirect to index.php...that sort of thing?

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    barney,

    Yep!

    The beauty of using the "handler file" is that it's your choice where you send someone attempting to access your website without using your links (typing directly, hacking, whatever). I took the lazy route for WW by sending those guys to the Home Page but you could also use a 404 page with an amplified TOC (WW's complete TOC is on EVERY page) and an explanation that visitors must use the correct links or not be served their requested content.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •