How to permanent 301 redirect your olddomain to a new domain?

Here few fast track to make your htaccess redirects more in easy way.

How to permanent 301 redirect your olddomain to a new  www domain?

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

How to permanent 301 redirect your old domain to new non-www domain?

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

How to redirect all links of a domain except the domain name?

Options +FollowSymlinks
RewriteEngine on

#ip to allow access
RewriteCond %{REMOTE_HOST} !^11\\.11\\.11\\.11$

#send to root
RewriteRule (.*)$ http://www.iseleyrealty.com/$1 [R=302,L]

How to redirect all links of a domain except the domain name and few file path.

Now if you put a dummy html page as a demo to your root and all the related files under

/html/style.css

/html/logo.png

It will also be redirecting all files path to the newdomain.

As a modifcation you will also need to exclude this path.

Options +FollowSymlinks
RewriteEngine on

#urls to exclude
RewriteCond %{REQUEST_URI} !^/html/style.css$
RewriteCond %{REQUEST_URI} !^/html/logo.png$
RewriteCond %{REQUEST_URI} !^/$

#ip to allow access
RewriteCond %{REMOTE_HOST} !^11\\.11\\.11\\.11$

#send to root
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]

 

Leave a Comment