Forum Moderators: phranque
<VirtualHost www.domain.tld>
DocumentRoot /path/to/site/files
ServerAdmin user@domain.tld
ServerName www.domain.tld
ServerAlias domain.tld
</VirtualHost>
As for why - I do it for type-ins. Probably less important than it used to be, since most browsers now will stick "http://www" in front of anything and try again before they give up on it. Enough people don't know that the www is part of the FQDN of the server they are trying to reach that I don't think I should count on them typing it.
It has occurrect to me to use 301 redirects instead, but that would just be more work. I might do it eventually to be just that much safer from a perception of duplicate content, but I really doubt SE spiders are that dumb.
Certainly, one could put different content on each of the domains if you so desired. I'm not sure why you would, though. It wouldn't exactly work as cloaking unless you had some control over who got links to www.domain.tld as opposed to domain.tld. Actually cloaking would be far easier than trying to maintain that kind of control over all links to your site.
There might be some underhanded reason to do it this way, but I doubt it. I'm certainly not coming up with any ideas.
[domain.com...] is *the* domain. The www-part was originally intended to reflect which server under the domain you accessed, thus as the internet started and you wanted to get www-content, you accessed the www-server, and html and www became synonymous. At present, the www-part can be anything and does get used for anything: [sales.domain.com...] ; [support.domain.com...] etc - you get the drift. Normally the domain both with and without the www serves the same content, but it's possible to server different content if you want to.
Personally, I'm using the something part of [something.domain.com...] to access pages deep inside the site as a kind of shortcut for certain functions so people end up at eg [domain.com...]
So, you've nothing to worry about - it's quite normal to see both versions used.
yours in happy hacking
Bjarne - København ; Danmark ; Europa
This is what is in my .htaccess file on the web root
It will take www.domain.com and permanently direct it to domain.com.
Suppose you want the url to always appear in the form [domain.com...] -- and that you want it to display that way whether or not the http and the www are included in the url typed in. What's the best way to set this up?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domainname [NC]
RewriteRule ^(.*) [domainname.com...] [R=301,L]
This is also something to keep in mind if you have other domains pointing to the same content. Example: have yourmainsite.net resolve to yourmainsite.com, don't let yourmainsite.net stay in the address bar.
Will PermanentRedirect also work in this case... and, if it would, what is the reason to use Mod Rewrite in preference to PermanentRedirect? I'm seeing that most experienced users on the board seem to favor Mod Rewrite (perhaps because it's more versatile?). Is it always preferable for redirects?
If I did use PermanentRedirect, what is the best syntax? I'd like all the urls to show with the www to avoid linking confusion.
RedirectPermanent won't do this job, because it is not "aware" of {HTTP_HOST} and therefore cannot discern when it does and does not need to redirect. There is no analogous function in RedirectPermanent to mod_rewrite's RewriteCond to provide for conditional redirects.
DaveAtIFG's rewrite above is very simple and effective. The biggest danger with mod_rewrite is if you make a typographical error, and then the results are immediate and obvious. :o Most can be "debugged" by looking at the raw error log - it usually identifies which line in .htaccess the server can't parse.
I have used the following, a hybrid of sun818's and DaveAtIFG's versions, for several years to redirect any request for any of my "registered, but non-standard domains" to www.mydomain.org:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org
RewriteRule ^(.*)$ http://www.mydomain.org/$1 [R=301,L]
Basically, if a visitor or 'bot requests mydomain.org, www.mydomain.com, WWW.MYDOMAIN.ORG, or any other non-standard variant of the domain name, they get neatly redirected to www.mydomain.org.
C'mon in, the water's fine! :)
Jim