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

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.

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

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 :slight_smile: )?

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

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?

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