Forum Moderators: phranque
1. Is that a reason of the massive backlinking from page_from_own_site with PR 0?
2. Is it wise now to "concentrate" the PR of www.mydomain.com and mydomain.com to a single page?
I found an example for mydomain.com -> www.mydomain.com
rewriteCond %{HTTP_HOST}!^www\.mydomain\.com
rewriteRule ^(.*)$ [mydomain.com...] [R=permanent,L]
but my favorite in this situation would be
www.mydomain.com -> mydomain.com because then the entire linking structure would be unchanged for the Google spider.
3. Is that the right aproach?
RewriteCond %{HTTP_HOST}!^mydomain\.com.*
RewriteRule ^http://www.mydomain.com(.*)$ [mydomain.com$1...] [R=permanent]
Thats working.
4. Can that be optimized?
Thanks, Maggy
Various characters, including periods, have special meaning in the regular expressions patterns used by mod_rewrite. The period must be escaped or it will mean "match any character." This code is right for your stated purposes if installed in httpd.conf:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteRule (.*) http://www.mydomain.com$1 [R=permanent,L]
If you have a DMOZ listing pointed to "www" and PR4 on that subdomain, then that's the one you should use. So redirect non-www to www using the code above. It will be far easier to update your site to consistently refer to www, than it will be to get your ODP listing changed and get Googlebot to switch the PR over.
On a new site, it does not matter which you use, the domain mydomain.com or the subdomain www.mydomain.com, but the best results will be had if you consistently use only one of them.
Don't use any code on your server until you fully understand it. I recommend the following references:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]
Jim
I want to make sure even if a person types mydomain.com they end up being 'redirected' to www.mydomain.com
When I tested your code it did not seem to work - is it supposed to do that?
I want to force everyone to only ever see www.mydomain.com.au no matter what they type.
The first is the one I've been using which I lifted from here a long time ago. The second is the one a friend is using. (the forum software changes some things after you post here, but the gist of the point is still the same)
RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
RewriteRule (.*) [domain.com...] [R=301,L]
--
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
The first version redirects all except "www.domain.com" to www.domain.com, while the second only redirects "domain.com" to www.domain.com. For a site where only these two domain variations exist, they do the same thing, but in different ways.
Also note that as member Gergoe has pointed out, the first version should always test to make sure that the {HTTP_HOST} is not blank, as it would be for HTTP/1.0 requests:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Jim
- What happens to subdomains? They dont seem to get redirected, but the code statement appears to say they should.?
- Is it better to redirect from www.domain.com to domain.com (so you only have essentially one domain live, since www is a subdomain itself) than redirect from domain.com to www.domain.com (where you end up having two domains live).
Oh, and we wondered what happens to PR (is it split between www.domain.com and domain.com). But that might be a question for another day and another thread in a different forum.
Would anyone like a beer?
There is no technical reason to prefer www vs. non-www. Make the choice based on existing incoming links, branding issues, and length of URLs.
If you have back-links of both www- and non-www forms, then it is possible that your PageRank is split across these two domains. Google usually resolves this for www- and non-www, but why depend on third parties when you can control it?
Jim