Redirecting the GET string with .htaccess

Some of our PHP scripts had different names but the GET string stayed the same. We needed to redirect the visitors to the new PHP scripts while preserving these GET strings. The GET string is the set of characters that come after a filename in the URL and are used to pass data to a web page. An example of a GET string in the URL http://www.strongwind89.com/myfile.php?this=that&foo=bar would be “?this=that&foo=bar.”

Redirect: http://www.socengine.com/seo/categorydetail.php?CAT_ID=12345
To: http://www.strongwind89.com/artcat.php?CAT_ID=12345


Add the following directive:
RedirectMatch 301 /seo/categorydetail.php(.*) http://www.strongwind89.com/artcat.php$1


Once again the regular expression (.*) tells apache to match zero or more of any character and save it as the back-reference $1. Since we put $1 after /seo/categorydetail.php, it will now redirect the get string to this new php file.

No comments:

Live Page Popularity