Redirecting url with a rewrite rule

Lets suppose you have made some changes to your website and you want to redirect some pages to their new url format, this .htaccess rewrite rule might come in handy:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)subpage1/subpage2/mypage.html$
RewriteCond %{QUERY_STRING} Itemid=91&page=mypage$
RewriteRule ^(.*)$ http://mynewurl.com/index.php?mypage=new

What the above condition does is redirect /subpage1/subpage2/mypage.html?Itemid=91&page=mypage url to http://mynewurl.com/index.php?mypage=new

Obviously, you need to replace the above names with your actual site names

The second RewriteCond with QUERY_STRING is only needed if the url you want to rewrite has additional parameters like mypage.html?pages=mypage for instance

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Redirecting url with a rewrite rule”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>