Reputation:
I try to redirect list of url's with query strings, but these
rules are not working:
Redirect 301 /tg.php?uid=www567461d4d44a53.12485104 http://example.com/
Redirect 301 /test/?page_id=45 http://example.com/
Redirect 301 /?p=17518 http://example.com/
Redirect 301 /?page_id=5960 http://example.com/
Upvotes: 0
Views: 26
Reputation: 42935
Please read the documentation of the tools you use. Apache's mod_alias explicitly states that you should use the rewriting module if you need to examine the query string for the purpose of redirection and not the alias module. That means you should use RewriteRule
's instead of Redirect
rules:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^uid=www567461d4d44a53.12485104$
RewriteRule ^/?tg\.php$ http://example.com/ [R=301]
RewriteCond %{QUERY_STRING} ^page_id=45$
RewriteRule ^/?test/?$ http://example.com/ [R=301]
RewriteCond %{QUERY_STRING} ^p=17518$
RewriteRule ^/?$ http://example.com/ [R=301]
RewriteCond %{QUERY_STRING} ^page_id=5960$
RewriteRule ^/?$ http://example.com/ [R=301]
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug, they really slow down the http server, often for nothing and they can open pathways to security nightmares. They are only provided for situations where you do not have access to the real http servers host configuration (read: really cheap service providers).
Upvotes: 0