Forum Moderators: phranque

Message Too Old, No Replies

interpreting URLs non-literally

how do I interpret URLs non-literally

         

smithydude

9:35 am on Apr 17, 2009 (gmt 0)

10+ Year Member



Hello,

Please consider the following URLs:

www.example.com/find/roses
www.example.com/find/seeds
www.example.com/find/vases

Using my current set-up the server would look for a folder "find/seeds/" and display the index file inside.

However I would like one PHP file to interpret each of these URLs without these folders actually being on the server. This PHP file would look at the URL and display something different depending on the URL.

This is a fairly common task I imagine, but I haven't been able to find anything on it just yet.

Any help much appreciated!

smithydude

10:19 am on Apr 17, 2009 (gmt 0)

10+ Year Member



oops - think it's something to do the apache rewrite module.

g1smd

6:30 pm on Apr 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes. Set up two things:

1. Set up a redirect using RewriteRule to fix the URL to the correct format if a wrong, but almost right, URL was requested. So, strip trailing slash if included, and force www if non-www was requested.

2. Set up a rewrite using RewriteRule to capture the requested URL (and only URLs of the correct general format) and rewrite it to the internal file. Use a backreference to 'capture' the value in the URL request, and then append it to the target as a parameter.

Optionally, set up a redirect so that the script file cannot be directly accessed as a parameter-driven URL. Redirect those requests to the correct format.

Ensure that the script returns a 404 HTTP Header for any non-valid value otherwise you'll end up with massive problems.