Pergunta

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!

Foi útil?

Solução

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.

Outras dicas

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top