Basically I’d like to do a 301 re-direct from one specific dynamic page that has a question mark character (?) in the URL to a static page.
The reason I want to do this is that this page is effective for SEO, but it will benefit from its own page now. I’ve used Rewrite rules for redirecting query strings many times, but I can’t seem to figure how to escape, say, a specific url that has a ?. For example:
Redirect 301 /page.php?page_id=1 /new-page/
Redirect 301 /page.php?page_id=10 /cool-product/
I do not need to do the following:
RewriteRule ^page/([0-9]+)/([a-zA-Z0-9_-]+)/$ ./page.php?page_id=$1 [R=301,L]
3
Answers
You can make rules that are run against the query string using
mod_rewrite
like:Here is a decent write up on the topic: https://simonecarletti.com/blog/2009/01/apache-query-string-redirects/
You can not redirect url with querystrings to a static page using
Redirect
directive, you need to usemod-rewrite
,so try this :Empty question mark at the end of the target url is important as it discards the old query strins from the new url.
Strips all Query Strings that start with do= ONLY if the Request URI is classifieds/ and redirects to the /ads/ URI:
http://www.example.com/classifieds/?do=detailpage&cat=3&id=14
tohttp://www.example.com/ads/