måndag 19 januari 2009

Visa alltid/aldrig www i URL:en

Det är både tjusigare och underlättar sökmotoroptimeringen av hemsidan om hemsidans url är konsekvent. Detta kan man enkelt lösa med hjälp av .htaccess:

#Visa alltid www:
Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Visa alltid www, gäller både http och https:
Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^([^.]{4,}[^w.]?[^.][^w.]?[^.]?[^w.]?)..*//((s)ons.*) [NC]
RewriteRule ^ http%3://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Visa aldrig www, gäller både http och https:
Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)ons.*)$ [NC]
RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301]

#Visa aldrig www:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Om det inte fungerar på ditt webbhotell/webbserver så prova att skriva in hela ditt domännamn:
#Visa alltid www:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^dindomän\.se [NC]
RewriteRule ^(.*)$ http://www.dindomän.se/$1 [R=301,L]

#Visa aldrig www:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^dindomän\.se$ [NC]
RewriteRule ^(.*)$ http://dindomän.se/$1 [R=301,L]

Inga kommentarer: