Forum Moderators: phranque
I've used the following construction to no avail:
RewriteCond %{QUERY_STRING} ^q\=16$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
Straight redirects don't work because of the variable that exists in the first URL.
Any other suggestions for handling redirections on URL's with variables in 'em?
[edited by: jdMorgan at 2:20 am (utc) on Feb. 3, 2006]
[edit reason] De-linked. [/edit]
That allows me to map pages without any consideration for patterns or regular expressions in the URL's. What it doesn't do is map a dynamic page to another dynamic page.
Comment/warning only:
If you use the 404 error handler method, you need to be absolutely sure that the server response code is correct. You cannot allow the 404 error handler to return a 404-Not Found status for pages that *do* exist. Otherwise, you'll trash your search engine rankings.
Use a server headers checker [webmasterworld.com] to be sure...
Jim
RewriteCond %{REQUEST_URI} /page.php$
RewriteCond %{QUERY_STRING} ^q=([0-9]+)
RewriteRule ^.*$ /newfolder/page.php?q=%1 [R=301,L]
Two questions though:
1. How is %1 different from $1
2. What if I have this in the URL:
page.php?q=16+00001
The second line above doesn't seem to work then.
RewriteCond %{QUERY_STRING} ^q=[^&]+
RewriteRule ^page\.ph$ http://www.example.com/newfolder/page.php [R=301,L]
%1 is a back-reference to the first parenthesized value matched in the mosr-recently-matched RewriteCond, whereas $1 is a back-reference to the first parenthesized value matched in the RewriteRule. Neither are required in this case, because query strings are passed through unmodified by default -- unless you have other rules that are interfering.
Also, be aware that the redirect will only occur if the query string starts with "q=".
The pattern [^&]+ requires one or more characters not equal to an ampersand. This is in case you have other query name/value pairs following the "q=" stuff.
Obviously, there are many, many variations possible, so I took my best guess at what you're trying to accomplish.
Jim
I tried several things, including
RewriteCond %{QUERY_STRING} ^q\=16\+0001
but no luck.
RewriteCond %{QUERY_STRING} ^q=16\+0001
RewriteCond %{QUERY_STRING} ^q=16\%2b0001
Additionally, "+" may appear as an encoded entity in the query string, in which case it will match "%2b". I showed both cases, since I'm not sure how it appears inside %{QUERY_STRING} (please let us know!).
Jim
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/page\.php\?q=16 HTTP/
RewriteRule ^folder/page\.php$ http://www.domain.com/newfolder/page.php?q=16 [R=301,L]
[edited by: jdMorgan at 2:20 am (utc) on Feb. 3, 2006]
[edit reason] De-linked [/edit]