Some times we need to change your website url without impacting any issue with pages SEO. A page redirect with 301 permanent tells the search engines that new url has taken place of old url permanently. So search engines will remove old urls from there indexes.
Advertisement
Redirect from One File to Other File
This is helpful 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
Use this setting if you want to keep your site always running www url. This 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. This 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
Ever you want to change your website domain, 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]