Redirecting old Query String URLs to CMSMS pretty urls
Posted: Mon Feb 14, 2011 9:55 pm
All -
This took me about an hour and a half to figure out, so I wanted to post for other users who use CMSMS and are coming from old php sites.
Pretty URLs (mod_rewrite) does not correctly interpret 301 redirects in the .htaccess file when the original url has a query string in it: index.php?someID=someVal
So the following works to make the .htaccess mod_rewrite work correctly:
Below the rewrite engine rule is where to edit:
I used the following directionals based on an OLD url like this:
Notes:
The RewriteCond has the key-value pair that you have used in your old URLs. here it is "someID" and "someVal"
The RewriteRule has two important things. ^originalPage (this is the original page name from your site WITHOUT the extension .php or whatever)
the second important thing is to add the "?" after the last / - this removes the original query string from the new rewritten url.
I know this isn't totally a CMSMS issue, but this explanation is specifically for CMSMS so please leave this post.
It took me a while to figure this out.
If anyone has other things to add, please do....
-steff
This took me about an hour and a half to figure out, so I wanted to post for other users who use CMSMS and are coming from old php sites.
Pretty URLs (mod_rewrite) does not correctly interpret 301 redirects in the .htaccess file when the original url has a query string in it: index.php?someID=someVal
So the following works to make the .htaccess mod_rewrite work correctly:
Below the rewrite engine rule is where to edit:
Code: Select all
Options +FollowSymLinks
RewriteEngine on
# Rewrite all the old php pages to the new CMS pages
# by adding lines here...
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
Code: Select all
http://www.example.com/originalPage.php?someID=someVal
Code: Select all
RewriteCond %{QUERY_STRING} ^.*someID=someVal.*$
RewriteRule ^originalPage http://www.example.com/the/pretty/url/path/to/your/new/page/? [R=301,L]
The RewriteCond has the key-value pair that you have used in your old URLs. here it is "someID" and "someVal"
The RewriteRule has two important things. ^originalPage (this is the original page name from your site WITHOUT the extension .php or whatever)
the second important thing is to add the "?" after the last / - this removes the original query string from the new rewritten url.
I know this isn't totally a CMSMS issue, but this explanation is specifically for CMSMS so please leave this post.
It took me a while to figure this out.
If anyone has other things to add, please do....
-steff