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

Leave a Reply

Your email address will not be published. Required fields are marked *