How To Fix Canonical www (non www)

bougatsa
bougatsa's picture

Joined: 2012-03-30
Posts: 5
Posted: Fri, 2012-04-27 15:46

Hi,

I'm just in the process on configuring a new site running Gallery 3.

It looks like SEO is pretty good out of the box but I've added Mile Carter's Gallery 3 SEO tips to improve my URLs and pagination.

What I'm not sure of is how to fix canonical www (non www)? At the minute you can access both www and non-www versions of my domain.

Gallery 3 is in the root of my website. I want all URLs to resolve to http://www.mysite.com not http://mysite.com

Does anyone know how to do that in .htaccess alongside Miles' mod rewrite rules?

Neil

 
bigu_c
bigu_c's picture

Joined: 2007-10-28
Posts: 421
Posted: Fri, 2012-04-27 15:50

Add this to your .htaccess file in root folder:

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

Replace "domain.com" by "yourdomain".

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Fri, 2012-04-27 16:07
 
bougatsa
bougatsa's picture

Joined: 2012-03-30
Posts: 5
Posted: Sat, 2012-04-28 06:28

@bigu_c - Thanks, that's helpful.

@suprsidr - Yes, you're right, decided to go with non-www.

I added that code to .htaccess alongside the other rewrite rules from Miles' post. I had to add it at the end to get it to work.

 <IfModule mod_rewrite.c>
 
#External Rewrite – fixes pagination – http://www.milesjcarter.co.uk/blog/photos-on-the-web/gallery-3-seo-part-perfect-url-scheme/#
	RewriteCond %{THE_REQUEST} \?page=([0-9]+).*
	RewriteRule (.*) $1/page/%1? [R=301,L]
	RewriteRule (.*)/page/1 $1 [R=301,L]

#Internal Rewrite – fixes pagination#
	RewriteRule ^(.*)page/([^/\.]+)/?$ $1?page=$2 [L]
	
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^index.php/(.*) $1 [QSA,R,L]
   RewriteCond %{HTTP_HOST} ^www.clothingstyles.net
   RewriteRule (.*) http://clothingstyles.net/$1 [R=301,L]
   
 </IfModule>

It seems to be working fine. However, if I type in www version into a browser it redirects to

http://clothingstyles.net/index.php?kohana_uri=

Any ideas what's going on there?

I know .htaccess can cause havoc if you get it wrong so just want to make sure I'm doing everything very correctly.

Thanks
Neil

 
bigu_c
bigu_c's picture

Joined: 2007-10-28
Posts: 421
Posted: Sat, 2012-04-28 07:18

Clear your browser cache now.