I've got a fundamental Content management systems in PHP/MySQL where content managers can make pages somewhere for public viewing. Each page will be offered at an url for example http://www.example.com/pages.php?pid=123 Now, I wish to redirect demands to http://www.example.com/pages.php?pid=123 to http://www.example.com/pages.php?pid=456.

I have already removed the pid=123 page in the db but due to the content management systems code the website still returns a 202 when someone attempts to access the page. I figured I possibly could make use of a 301 redirect in .htaccess to create the redirect work, i.e.:

redirect 301 pages.php?pid=123 http://www.example.com/pages.php?pid=456

but this does not work, Apache still return 202 when attempting to fetch the pid=123 page. Also, I have attempted using mod_rewrite, however it does not work:

RewriteRule ^pages.php?pid=123$ pages.php?pid=456 [R=301,L]

Any ideas what is wrong and just how I'm able to fix the 301 redirect?

Both [cde] and [cde] directive work just around the URL path. In mod_alias (Redirect directive) you can't test the query as well as in mod_rewrite (RewriteRule directive) you'll need one more [cde] directive:

Redirect

However it would likely be superior in case your Content management systems are designed for such redirects since it’s your Content management systems that knows best what Web addresses are valid and what exactly are not.

You are able to carry out the redirect in PHP (which most likely knows much more about things to redirect where) using RewriteRule.

Please be aware that RewriteCond is really a special character utilized by regular expressions, so that your regex matches RewriteCond %{QUERY_STRING} (^|&)pid=123(&|$) RewriteRule ^pages\.php$ /pages.php?pid=456 [R=301,L] and header().

Even so, I do not think the query string (such as the ? part) can be used within the URL handled by pages.phppid=123, so you should use something similar to:

pages.phppid=123

This should not work out of the box, however it should provide you with ideas.