Forum Topic: www-canonicalization

Forum: .htaccess Forum : Redirecting • Posted by Carmelo Gonzalez • Updated:

Hi,

I have three doubts about this topic. I want to force the www-prefix for my first domain (I'm a begginer) and I'm using the code on page 62, my doubts are the followings:

1.- Why is neccesary to include all the RewriteCond and RewriteRule instructions into the IfModule section ?. I understand that the IfModule is used for testing if mod_rewrite module is not active and then to active it with RewriteEngine On but the rest of the instructions (RewriteCond and RewriteRule -the most importants-) into the IfModule section looks like its wiil be executed or not according to the condition. Is so ?

2.- A friend a little bit more experienced that me uses the following for www-canonicalization:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^hisdomain.es$
RewriteRule ^(.*)$ http://wwww.hisdomain.es$1 [R=301]

What are the diferences between both instructions set in terms of effectiveness?

3.- In addition to my principal domain (mydomain.net) I have three additionals domains for the same blog as parked domains pointing to the principal (mydomain.eu, mydomain.org, mydomain.es). The question is, Have I to include additionas things in order to optimize the canonicalization or any other thing related with SEO ?

Many Thanks in advance. I'm a begginer and I would appreciate the help that you could give me.

Carmelo.

10 Replies to “www-canonicalization”

Jeff Starr
Posted by Jeff Starr

Hi Carmelo,

Let me try to respond to these questions:

1. The IfModule sections are included with many of the code samples for the sake of portability, so that users don't have to look elsewhere to find the IfModule containers if they're needed. Some people use them as you've described, others use them for each set of rules so that things don't break if something changes.

2. Let's look at each method side by side:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^hisdomain.es$
RewriteRule ^(.*)$ http://wwww.hisdomain.es$1 [R=301]

# require www
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>

Both of these do the same thing, with the main difference that no editing is required for the one from page 62. Both methods check the HTTP_HOST for the presence of the www prefix, and then proceed to rewrite the URL if it's a match. Using either technique should yield the same results. I prefer the book version simply because it's entirely plug-n-play, no editing required, so it works on any site I add it to.

3. I'm sort of confused by this question, hopefully you wouldn't mind explaining further so I can better understand and try to help?

Regards,

- Jeff

Posted by Carmelo Gonzalez •

Hi Jeff,

Sorry for the delay and for my bad english, it's not easy to understand it and in addition, normally I need to use longer phrases to express something that probably couldd be done with two or three words.....

Regarding to the point 3 let me explain it. I have my principal domain mydomain.net and I have done the canocalization for requiring the www and it's working fine. In addition, I own the same domain name for .es, .eu and .org (mydomain.es, mydomain.eu and .org). All of them as my principal blog.

I have this three others domains in park status on my host provider pointing all of them to my principal domain (mydomain.net). So, any visitor will access to my blog with any of this others three domains (and ofcourse with mydomain.net -canonicalized for requiring www-).

So I would like to do a configuration for avoid duplicate contain posibility for all this other three domains in adition to the principal .net and in all the cases the final URL showed as www.mydomain.net.

If I apply the canonicalization the result would be www.mydomain.xxx, so what is the best configuration for the final canonicalization is www.mydomain.net for SEO optimization.

The question looks like a boring book ;)

Thanks in advance,

Regards.

Jeff Starr
Posted by Jeff Starr

Okay thank you, it makes sense now :) I think that there is no need to canonicalize those URLs if they are being redirected to another domain.. it only matters that the principal domain is canonicalized, unless there is some way that a visitor can land on and view, say, mydomain.es or mydomain.eu..? In other words, it should not matter whether the redirects happen via www.mydomain.eu or mydomain.eu because they both end up at your canonicalized principal domain. Unless I'm not understanding.. please let me know your thoughts.

Posted by Carmelo Gonzalez •

The thing is that although visitors see the same content, the URL in the browser on the landing page (the principal page of the blog) is still the URL for each case. i.e. if the visitors arrives from mydomain.es the URL on the browser is medomain.es and not www.mydomain.net.

So, this besides being not very aesthetic (the URL changes after that if the user access any content) casts doubt me ahead of SEO.

Thanks in advace again,

Carmelo.

Posted by Carmelo Gonzalez •

One aditional clue...

I can't understand why the canonicalization (forcing www prefix) works for mydomain.net but not for mydomain.es nor mydomain.eu nor mydomain.org.

I'm using the code at page. 61

Maybe I need to call the ghostbusters....

What do you think ?

Regards,

Carmelo.

Jeff Starr
Posted by Jeff Starr

Hmm.. very interesting. Have you tried placing the redirect rules in the .htaccess file on the non-principal domains? So that the principal domain has the www rules, and each of the others contains the appropriate redirect rules as well?

Posted by Carmelo Gonzalez •

I think so. This is as I have it:

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

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^mydomain.es$ 
RewriteRule ^(.*)$ http://wwww.mydomain.net$1 [R=301,L]

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^mydomain.eu$ 
RewriteRule ^(.*)$ http://wwww.mydomain.net$1 [R=301,L]

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^mydomain.org$ 
RewriteRule ^(.*)$ http://wwww.mydomain.net$1 [R=301,L]

When I type mydomain.net the URL changes to www.mydomain.net but mysteriously when I type i.e mydomain.es the home pages is showed but the URL still mydomain.es and the same behavior when typing mydomain.eu and mydomain.org. Just looks like ignore al three aditionals rule sets.

Posted by Carmelo Gonzalez •

Opsss. For each rule set I included (in my previous post) the IfModule but doesn't shows it. Ignore me too.

Definitely, I need a Ghostbuster.

Jeff Starr
Posted by Jeff Starr

Okay I think I see the problem.. are all of those rules in the same .htaccess file (for the principal domain)? Only the first block of rules (the www stuff) should be placed in the principal domain, each of the other blocks of code need to be placed in the .htaccess file of its respective domain. So each domain has its own .htaccess rules.

Posted by Carmelo Gonzalez •

Yeahhh. That was the problem but at first I did not understand very well because I had only one root directory for the principal domain but not for each parked domain. So I had to remove the parked domains and re-adding them as addons domains to the principal. So, now I have a directory for each one with the corresponding .htaccess.

So, the canonicalization is working nice.

Thanks a lot.

Regards.

Carmelo.