Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule syntax

Please help!

         

AnonyMouse

4:09 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



Hi,

I'd like to redirect
www.mydomain.com/en/apartments/name.html
to
www.mydomain.com/apartmentpage.php?lang=en&name=name

I tried this:
RewriteRule ^en/apartments/test.html$ /apartment-redirect.php?path=$1

This does the redirect, but the $path isn't passed through. (I was then going to do some php on the $path to get my $lang and $name)

Any suggestions much appreciated!

jdMorgan

4:25 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to pass part of the URL-path through as a query-string name/value pair, you have to create a pattern that will match it before you can back-reference it as $1 through $9...

RewriteRule ^en/apartments/([^.]+)\.html$ /apartment-redirect.php?path=$1 [L]

Here, the subpattern used to 'extract' $1 means "One or more characters not equal to a literal period."

Note that the following literal period must be escaped; Unescaped periods in regex patterns are tokens meaning "match any single character."

Also, always use the [L] flag unless you have a good reason not to...

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim