Question

I need to 301 redirect one URL to another. Now I have this rule in .htaccess

RewriteRule /forum/viewtopic.php?f=65&t=6 /page/name-of-the-page [R=301]

RewriteRule /forum/viewtopic.php?f=30&t=5 /page/another-name-of-the-page [R=301]

But it doesnt work at all. Could please anybody help me with that?

Thank you very much in advance!

Was it helpful?

Solution

You cant match query string using RewriteRule. Use it like this:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^f=65&t=6$
RewriteRule ^forum/viewtopic\.php$ /page/name-of-the-page? [R=301,L]

RewriteCond %{QUERY_STRING} ^f=30&t=5$
RewriteRule ^forum/viewtopic\.php$ /page/another-name-of-the-page? [R=301,L]

? in the end is used to strip-off any existing query string.

OTHER TIPS

RewriteRule /forum/viewtopic.php?f=30&t=5 /page/another-name-of-the-page [R=301]
RewriteRule /forum/viewtopic.php?f=65&t=6 /page/name-of-the-page [R=301]

just reverse the order and it should work!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top