Forum Moderators: phranque
Also is mod-rewrite required to do this or is it possible to simply do a permanent one line redirect instead?
Thanks.
The mod_rewrite version is possible two ways:
# Necessary to both sets below
RewriteEngine ON
# Option 1 - Positive Check:
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
The above ruleset checks to see if the host is the www. version of your domain, and if so, rewrites that to the non-www. version.
# Option 2 - Negative Check: (My Preference)
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yoursite\.com [NC]
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
The above ruleset checks to see if the HTTP_HOST is set (HTTP 1.0 clients do not send a HOST header, so they would end in a loop if there was no check). Then if there is a HOST, the second condition checks to see if the HOST is *not* yoursite.com - if it is not, the rule is applied and the URL is rewritten.
I like the negative check for a couple of reasons:
1. If someone mistypes a subdomain EG wwww.yoursite.com they will be correctly redirected
2. In some cases you will break framing scripts from placing your site in a frame set.
Hope this helps.
Justin
I'm hoping there's something I can write into my .htaccess file to let people go straight to the site, as they seem to be able to do on just about every other site.
As you can likely tell, I'm not a programmer! Any help appreciated.
AllowOverride FileInfo
Options +FollowSymLinks
Again, I like the negative ruleset better.
Have you tried either?
If not, make sure you create the file (or edit if it exists) in a *plain* text editor, and you upload in ASCII mode.
Justin
We're on a shared server so I don't have access to any other top level server administration files beyond the .htaccess - does this matter?
I've got redirects in my .htaccess for error 404 pages and the like, so that much I have worked out - advice beyond that would be very welcome.
www.domain.com
It cannot be seen using:
domain.com
And it doesn't make any difference whichever version of these mod_rewrite commands I use.
Was thinking it was a DNS issue that could be solved with CNAME, but I haven't the slightest idea how to sort that.
Basically, I want people trying to access the site without using the www. in front of the domain name to be able to get to it, which presently they can't.
The host is Active24 here in the UK.
If it still doesn't work after doing that, ask your host to enable wildcard subdomains on your acount.
Jim
We have a shared server, so I can only change things like the .htaccess file - I don't have administrative access to the server set-up.
It's really maddening - just about every site seems to be able to show itself with or without a www. except ours!