Viewing Article

No StarNo StarNo StarNo StarNo Star | Nov 4 2017, 11:12 AM | Print
htaccess
The smoothest way to redirect your visitors is to use an .htaccess redirect. This has no delay since before a page is served to the browser the server checks first for an .htaccess file... if it sees this the old page never loads, instead visitors are sent directly to the new page.

301 Redirect

To Move a single page : ( Quick, easy and seamless for your visitors. )

Redirect 301 /oldpage.html http://www.example.com/newpage.html

Move an entire site : ( This will catch any traffic on your old site and redirect it to your index page on your new server. If you want to redirect each page to its new spot, this isn't the one for you. )

Redirect 301 / http://www.example.com/

Redirect www to non www version of site

It's best to stick with either always using www.example.com or just example.com. Allowing both can confuse the search engines. So here's how to force your site to always show the non-www version. (Search for "canonical url errors" in your favorite search engine for more info.)

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

Redirect non-www to www

Same as above except in the reverse, this one forces the www. into your url.

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

Redirect example.com/index.php to example.com/

Another snippet that I've heard is a good idea to make sure search engines don't give you a duplicate content penalty, this will also redirect example.com/folder/index.php to example.com/folder/.

Options +FollowSymLinks
RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]