[Pro] canonical rewrite question for sub-domains

Hi all,

I have a basic rewrite rule working from non-www to www, but I have since added a search feature to my site on three different sub-domains, and want to know if the following code to achieve the same thing on the sub-domains will cause any SEO damage or not? It works, but is it OK? Thanks in advance.

RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain1.mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.subdomain1.mydomain.co.uk/search/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain2.mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.subdomain2.mydomain.co.uk/search/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain3.mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.subdomain3.mydomain.co.uk/search/$1 [R=301,L]

freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You can do that, but I would actually do it the opposite way. If someone enters www.subdomain.domain.com, they are making a classic error. www IS a subdomain. Adding www in front of another subdomain is like making a sub-sub-domain. It’s a little silly. So sure, correct the error, but correct the real error and strip www off the subdomain if the user added it.

Walter

On Apr 26, 2012, at 7:30 AM, “Jonathan Riddle” email@hidden wrote:

Hi all,

I have a basic rewrite rule working from non-www to www, but I have since added a search feature to my site on three different sub-domains, and want to know if the following code to achieve the same thing on the sub-domains will cause any SEO damage or not? It works, but is it OK? Thanks in advance.

RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.)$ mydomain.co.uk - This website is for sale! - mydomain Resources and Information. [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain1.mydomain.co.uk$ [NC]
RewriteRule ^(.
)$ mydomain.co.uk - This website is for sale! - mydomain Resources and Information. [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain2.mydomain.co.uk$ [NC]
RewriteRule ^(.)$ mydomain.co.uk - This website is for sale! - mydomain Resources and Information. [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain3.mydomain.co.uk$ [NC]
RewriteRule ^(.
)$ mydomain.co.uk - This website is for sale! - mydomain Resources and Information. [R=301,L]


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,

So what you are saying here is that it is correct to show:
www.mydomain.co.uk

And it is correct on the subdomain to be:
subdomain.mydomain.co.uk

It shouldn’t have the www on subdomains?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Another issue I seem to have is that because my www rewrite for the main domain is contained within the same htaccess file as the subdomain rewrites, no matter what I do the subdomains are getting written with www in front of them anyway.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Use the ^ to anchor the beginning of the domain in your condition test. So if the request matches ^domain.com, rewrite it to www.domain.com

Walter

On Apr 26, 2012, at 10:46 AM, “Jonathan Riddle” email@hidden wrote:

Another issue I seem to have is that because my www rewrite for the main domain is contained within the same htaccess file as the subdomain rewrites, no matter what I do the subdomains are getting written with www in front of them anyway.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

www has no special meaning in the context of a domain name, it’s just traditional to use it as the “machine name” for your web server. The only part that’s really required is the protocol: http:// – that’s what makes the server wake up and pay attention.

Walter

On Apr 26, 2012, at 9:43 AM, “Jonathan Riddle” email@hidden wrote:

Hi Walter,

So what you are saying here is that it is correct to show:
www.mydomain.co.uk

And it is correct on the subdomain to be:
subdomain.mydomain.co.uk

It shouldn’t have the www on subdomains?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

My code does include the ^ doesn’t it?

I think I may not be able to achieve quite what I want, but I will explain the set-up anyway.

I have a mixed static (Freeway) and database driven site. I have a root htaccess file for the static section solving the fact I want www in the main domain - it is in that file I have the code above, and maybe where I am going wrong is trying to rewrite urls on the subdomains for the Open Cart installation (which is in a folder called /search).

That /search folder is effectively my root for the Open Cart installation - hence mydomain.co.uk - This website is for sale! - mydomain Resources and Information.. My three subdomains in cPanel point at root, and then in the Open Cart admin the three subdomains then have to point at the /search folder which has the base Open Cart installation installed. In that folder I have another htaccess file geared specifically for SEO friendly urls in Open Cart:

RewriteBase /search/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

I have tried adding the subdomain rewrites in there and nearly brought the internet down! I won’t be touching that again!

I will live with the subdomains having www in front of them, providing it doesn’t upset Google too much.

As for www or not to www. I was always under the impression that a site will appear as www.mydomain.co.uk and also mydomain.co.uk and Google will consider that to be two sites, with identical content, and so result in poor SEO results. Maybe that is old school, but I do much prefer www.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

All true, but in the case of an existing subdomain, adding a sub subdomain is just silly in my opinion.

Walter

On Apr 26, 2012, at 11:38 AM, “Jonathan Riddle” email@hidden wrote:

As for www or not to www. I was always under the impression that a site will appear as www.mydomain.co.uk and also mydomain.co.uk and Google will consider that to be two sites, with identical content, and so result in poor SEO results. Maybe that is old school, but I do much prefer www.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I do agree, but it would mean me losing the www from my main domain, so I will just have to stay silly until I work something else out :wink:

Thanks very much for your input as usual, Walter.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options