Articles & Code Snippets


.htaccess redirect

.htaccess redirect


Your website can be accessed with www.domain.com and domain.com. Since Google penalizes this due to duplicated content reasons, you have to stick your domain to either www.domain.com or domain.com. You can fix this easily with .htaccess:

Apache .htaccess redirect

Ex: to redirect all traffic from http://domain.com to http://www.domain.com

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

To redirect http://www.domain.com/index.php to http://www.domain.com

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L]

Option 2:

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

  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
  RewriteRule ^index\.php$ http://domain.com/ [R=301,L]
web


Archives