I recently asked a question about getting a specific Rewrite to work. I did get a working answer for that and used it on one of my sites. Now I’m trying to reuse this approach, but I’m finding that the logic is falling through to the WordPress Rewrite section and my own redirects are not being triggered at all.
# BEGIN Redirect deprecated site links to wp equivalent
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^news=13$
RewriteRule ^news_comments.php$ http://example.com/example-directory/ [R=301]
RewriteCond %{QUERY_STRING} ^news=51$
RewriteRule ^news_comments.php$ http://example.com/example-page.php [R=301]
</IfModule>
# END Redirect deprecated site links to wp equivalent
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I obviously need the WordPress rewrites, but I need for the ones that I specify at the top to be triggered and skip over the WordPress rules.
I’ve searched around and seen some suggestions of using something like…
...
RewriteCond %{QUERY_STRING} ^news=51$
RewriteRule ^news_comments.php$ http://example.com/example-page.php [R=301]
RewriteRule ^news_comments.php$ - [L]
</IfModule>
…but I just can’t seem to get it to work. Any ideas?
You need to make sure to add
[L]
flags to the end of your redirects, otherwise the URI continues its way through the rest of the rules and the redirect happens at the end. By then, wordpress has already had its way with the URI.