Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite: domain.com/red.html --> domain.com/find.php?s=red

mod_rewrite redirection help wanted

         

iantresman

4:59 pm on Jul 24, 2004 (gmt 0)

10+ Year Member



Can someone help me get my head around a mod_rewrite which involves truncating a %{REQUEST_URI}...

I am displaying the page:
[domain.com...]

...and want to display the dynamically generated page:
[domain.com...]

{REQUEST_URI} = red.html, but I want just "red". I have a hunch that backreferences could help?

Regards,
Ian Tresman

jdMorgan

5:18 pm on Jul 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ian,

Welcome to WebmasterWorld [webmasterworld.com]!

The problem can be broken down into two parts: First, you need to unambiguously recognize requests for /red in the proper position in the requested URL, and second, you need to rewrite that URL so that it references your find.php script with the appropriate query string taken from a back-reference to the original URL.

The first part is accompished by using regular-expressions pattern matching on the requested URL, and the second part is accomplished by the URL-rewriting functions of RewriteRule. I have posted some references at the end of our charter [webmasterworld.com] that may be useful to you.

Jim