How to Set Up 301 Permanent Redirect via .Htaccess

Some times we need to change our website URL without affecting pages SEO. A 301 permanent redirect of page tells the search engines that new URL has taken place of old URL permanently. So search engines will remove old URL’s from there indexes.

Redirect from One File to Other File

This is good if you want to redirect page from http://yourdomain.com/old.html to http://yourdomain.com/new.html.

Redirect 301 /old.html /new.html

Redirect Site to WWW URL

You can use these settings if you want to keep your site always running www URL . This is also helpful for SEO.

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

Redirect Site to Non WWW URL

If you want to keep your site to run always without www URL . It has there own pros and cons. Like using cookies on site.

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

Redirect Entire Site to New Domain

If you want to change your website domain name, you can easily redirect all pages from old URL to new URL .

Redirect 301 / http://newdomain.com/

Or you can use following settings.

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

That’s all we have to do. You also like to know How To Set Up A Permanent 301 Redirect Using PHP. Please check and give your opinion below if you experience any issues or to discuss your ideas and experiences.

Leave a Reply

Register to Get FREE Offers

Why Pay for Software when you can GET it for FREE

JOIN US TONIGHT!