Forum Moderators: phranque
Hi, I don't understand why this simple redirect doesn't work.
I've a Wordpress installation and I'm going to add a rule to redirect a page from an old site that was there.
I want to redirect /home/index.php?page=banner to /
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# My RULE:
RewriteRule ^home/index\.php\?page=banner$ / [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress It redirects to:
http://www.example.org/?page=banner
insted of
http://www.example.org/
I tried other variants, such as:
Redirect 301 /home/index.php?page=banner http://www.example.org
RewriteRule ^home/.*$ / [L]
But none seems to work. Could anyone help? Thanks.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /home/index\.php\?page=banner\ HTTP/
RewriteRule ^home/index\.php$ http://www.example.com/? [R=301,L]
The question mark at the end of the RewriteRule substitution URL is an operator not a literal, and serves to clear the current query string.
As for your box-stock WP rewrite rule, it's slow and inefficient. See this recent thread [webmasterworld.com] for a detailed discussion of cleaning it up and speeding it up by a factor of 2 at minimum.
Jim
[edit] Corrected as noted below. [/edit]
[edited by: jdMorgan at 5:22 pm (utc) on Jan. 8, 2010]
But the the code above doesn't seem to work, I cannot understand why, I checked the documentation of THE_REQUEST, other examples and it looks damn correct.
I narrowed my .htaccess in local machine to only this:
RewriteEngine On
RewriteBase /
RewriteCond ${THE_REQUEST} ^[A-Z]+\ /home/index\.php\?page=banner\ HTTP/
RewriteRule ^home/index\.php$ http://example.local/? [R=301,L]
And the browser returns 404 Not Found. This is the line in Apache access.log:
127.0.0.1 - - [08/Jan/2010:00:07:14 +0100] "GET /home/index.php?page=banner HTTP/1.1" 404 212
It looks correct to me :¦
In the meanwhile I found another couple of directives that do work:
RewriteCond %{QUERY_STRING} ^page=banner$
RewriteRule ^home/index\.php$ http://example.local/? [R=302,L]
But I'm still courious why the one with THE_REQUEST doesn't work, it appears to be correct and it may be useful in the future :(
Look at the log entries for these requests: The RewriteCond %{THE_REQUEST} pattern must match the quoted client request line that you see on your logs, starting with "GET" and ending with "HTTP/1.1" or "HTTP/1.0".
Jim