Canonical URL via modrewrite

Is something wrong? Do you have any suggestions? Let us know.
User avatar
ross
Dies with sente
Posts: 92
Joined: Wed Apr 21, 2010 4:40 pm
Rank: DGS 9k
GD Posts: 1315
Location: シアトル
Has thanked: 24 times
Been thanked: 36 times

Canonical URL via modrewrite

Post by ross »

As others have mentioned, this can affect logging in issues, SEO, etc., so best to get this sorted quickly. You need an .htaccess file in the root of your domain, modrewrite enabled, and this text in the file:

Code: Select all

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


This will ensure that if somebody leaves off the "www", or visits the site using another domain name that points here, the URL will get canonicalized to its proper, "one true form". There can be only one!
User avatar
ChradH
Dies with sente
Posts: 106
Joined: Wed Apr 21, 2010 8:40 am
Rank: EGF 8k
GD Posts: 0
Universal go server handle: ChradH
Location: Germany
Has thanked: 64 times
Been thanked: 7 times

Re: Canonical URL via modrewrite

Post by ChradH »

ross wrote:This will ensure that if somebody leaves off the "www", or visits the site using another domain name that points here, the URL will get canonicalized to its proper, "one true form". There can be only one!

One question: Are you suggesting to add "www." to every url? How about the other way round?

I find this "www." prefix highly redundant and really hate sites that only work when it's added. Please, let's keep it short and simple.
To sig or not to sig, that is the question.
User avatar
Chew Terr
Gosei
Posts: 2060
Joined: Mon Apr 19, 2010 12:45 pm
Rank: KGS 3k
GD Posts: 264
KGS: Chew
Location: Texas
Has thanked: 546 times
Been thanked: 172 times
Contact:

Re: Canonical URL via modrewrite

Post by Chew Terr »

He/they are making it so that you do NOT have to add the www. Fear not =)
Someday I want to be strong enough to earn KGS[-].
User avatar
ross
Dies with sente
Posts: 92
Joined: Wed Apr 21, 2010 4:40 pm
Rank: DGS 9k
GD Posts: 1315
Location: シアトル
Has thanked: 24 times
Been thanked: 36 times

Re: Canonical URL via modrewrite

Post by ross »

ChradH wrote:One question: Are you suggesting to add "www." to every url? How about the other way round?

I find this "www." prefix highly redundant and really hate sites that only work when it's added. Please, let's keep it short and simple.

The site will work either way, it's just a matter of how it shows up in the URL bar (and how search engines and cookies treat it, etc). I'm agnostic as to which way is better, I just think it should be standardized. You probably don't even notice the sites that put it on automatically for you, only the misconfigured sites that don't allow the "www." at all.
User avatar
fwiffo
Gosei
Posts: 1435
Joined: Tue Apr 20, 2010 6:22 am
Rank: Out of practice
GD Posts: 1104
KGS: fwiffo
Location: California
Has thanked: 49 times
Been thanked: 168 times

Re: Canonical URL via modrewrite

Post by fwiffo »

I don't care which version we use, we just need to pick one. I've actually been having DNS issues with the www version, weirdly enough, so I guess I favor the shorter version...
User avatar
ChradH
Dies with sente
Posts: 106
Joined: Wed Apr 21, 2010 8:40 am
Rank: EGF 8k
GD Posts: 0
Universal go server handle: ChradH
Location: Germany
Has thanked: 64 times
Been thanked: 7 times

Re: Canonical URL via modrewrite

Post by ChradH »

ross wrote:The site will work either way, it's just a matter of how it shows up in the URL bar (and how search engines and cookies treat it, etc). I'm agnostic as to which way is better, I just think it should be standardized. You probably don't even notice the sites that put it on automatically for you, only the misconfigured sites that don't allow the "www." at all.

I'm with you there, having one canonical address is a must. And though I might survive having "www." pasted in front of the sleek and elegant lifein19x19 I just typed into the address bar, I'd like it better without.

So it's the misconfigured sites forcing me to add the "www." which drive me mad.

*twitch*

Mad... maaad... MAAAD.... !!! :mrgreen:
To sig or not to sig, that is the question.
User avatar
kirkmc
Lives in sente
Posts: 1072
Joined: Tue Apr 20, 2010 3:51 am
Rank: 5K KGS
GD Posts: 1165
KGS: Dogen
Location: Stratford-upon-Avon, England
Has thanked: 32 times
Been thanked: 70 times
Contact:

Re: Canonical URL via modrewrite

Post by kirkmc »

fwiffo wrote:I don't care which version we use, we just need to pick one. I've actually been having DNS issues with the www version, weirdly enough, so I guess I favor the shorter version...


Hmm, I don't see that we "need" to pick one; both work, and it's a pretty standard "hack" for websites. I do it on all mine. If there's a DNS issue, that'd be somewhat odd - no one else has posted about DNS issues for the URL.
My blog about Macs and more: Kirkville
User avatar
ross
Dies with sente
Posts: 92
Joined: Wed Apr 21, 2010 4:40 pm
Rank: DGS 9k
GD Posts: 1315
Location: シアトル
Has thanked: 24 times
Been thanked: 36 times

Re: Canonical URL via modrewrite

Post by ross »

kirkmc wrote:Hmm, I don't see that we "need" to pick one; both work, and it's a pretty standard "hack" for websites. I do it on all mine. If there's a DNS issue, that'd be somewhat odd - no one else has posted about DNS issues for the URL.

By "pick one" we mean standardize on one to 301-redirect the others to (for aforementioned SEO, cookie, etc. issues).
xed_over
Oza
Posts: 2264
Joined: Mon Apr 19, 2010 11:51 am
Has thanked: 1179 times
Been thanked: 553 times

Re: Canonical URL via modrewrite

Post by xed_over »

kirkmc wrote:Hmm, I don't see that we "need" to pick one; both work,

Yes we do, Ross is right.

But not "we" (public), "we" (site owners/admins). It will be practically invisible to we-public.

Because of tracking cookies and such, there needs to be only one site. All others should redirect to it.
unkx80
Lives with ko
Posts: 257
Joined: Tue Apr 20, 2010 12:21 am
Rank: Dan player
GD Posts: 0
Location: Singapore
Has thanked: 13 times
Been thanked: 30 times
Contact:

Re: Canonical URL via modrewrite

Post by unkx80 »

Yes, better to just redirect the www. version to the version without www. (or the other way round). Then people and search engines will see and bookmark only one version.
xed_over
Oza
Posts: 2264
Joined: Mon Apr 19, 2010 11:51 am
Has thanked: 1179 times
Been thanked: 553 times

Re: Canonical URL via modrewrite

Post by xed_over »

people are still having trouble with this issue. what's the status?
User avatar
Jordus
Site Admin
Posts: 1125
Joined: Fri Dec 04, 2009 6:06 pm
Rank: KGS 9k
GD Posts: 0
Universal go server handle: Jordus
Location: Allegan, MI, USA
Has thanked: 16 times
Been thanked: 116 times
Contact:

Re: Canonical URL via modrewrite

Post by Jordus »

We think we have found the problem. We will try fixing soon during a period of low traffic.
I'm thinking...
User avatar
ross
Dies with sente
Posts: 92
Joined: Wed Apr 21, 2010 4:40 pm
Rank: DGS 9k
GD Posts: 1315
Location: シアトル
Has thanked: 24 times
Been thanked: 36 times

Re: Canonical URL via modrewrite

Post by ross »

Jordus wrote:We think we have found the problem. We will try fixing soon during a period of low traffic.

Ummmm... did you find that you need to have a canonical URL, and you're going to use modrewrite to do a 301 redirect? :mrgreen: Or are you attempting some other solution?
User avatar
Jordus
Site Admin
Posts: 1125
Joined: Fri Dec 04, 2009 6:06 pm
Rank: KGS 9k
GD Posts: 0
Universal go server handle: Jordus
Location: Allegan, MI, USA
Has thanked: 16 times
Been thanked: 116 times
Contact:

Re: Canonical URL via modrewrite

Post by Jordus »

ross wrote:
Jordus wrote:We think we have found the problem. We will try fixing soon during a period of low traffic.

Ummmm... did you find that you need to have a canonical URL, and you're going to use modrewrite to do a 301 redirect? :mrgreen: Or are you attempting some other solution?


Originally I came across this on a phpbb3 site:

I would suggest you set your cookie domain in phpbb and all products to this

.domain.com

reason being if someone clicks some link and there is not a www in it or say they login in phpbb without the www the cookie is not recognized on www or vice versa with no www depending on how they login. with a cookie domain of .domain.com your users will be logged in continuously nomatter the subdomain.

Also if logging in through PHPBB make sure they click the remember me button to create a cookie since our products work with cookies not sessions.
\

However fwiffo pointed out the mod rewrite should be done too for other reasons. So we are going to try the modrewrite first.
I'm thinking...
User avatar
Jordus
Site Admin
Posts: 1125
Joined: Fri Dec 04, 2009 6:06 pm
Rank: KGS 9k
GD Posts: 0
Universal go server handle: Jordus
Location: Allegan, MI, USA
Has thanked: 16 times
Been thanked: 116 times
Contact:

Re: Canonical URL via modrewrite

Post by Jordus »

Added the mod rewrite and changed cookie info. works for me. Anybody else?

Hint: be sure to clear cookies and restart browser first.
I'm thinking...
Post Reply