Some Redirect rules – really helpful ones

Redirect www to non-www:
========================

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Redirect non-www to www:
=======================

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

Redirect main site to subdirectory
==================================
RewriteEngine on
RewriteCond %{HTTP_HOST} ^hotelespara2.co.com$
RewriteRule (.*) http://www.hotelespara2.co.com/$1 [R=301,L]
RewriteRule ^$ blog/home/ [L]

Another one with symbol ‘?’ in URL.

==============================================================
www.domain.com/index.php?main_page=index&cPath=44

If you want the above URL should resolve to

http://domain.com/st_main.html?m=wedding-ceremony-programs-wedding-program-paper&p_catid=8

then use the following pattern,

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{QUERY_STRING} main_page=index&cPath=44
RewriteRule ^index.php$ “http://www.domain.com/st_main.html?m=wedding-ceremony-programs-wedding-program-paper&p_catid=8” [R=301,L]
===============================================================

Leave a Reply

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