Forum Moderators: phranque
I've never managed to get this to work. I'm re-visiting it again as I have a little spare time.
Have tried it two ways:-
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mydomain\.org [NC]
RewriteRule (.*) http://www.mydomain.org/$1 [R=301,L]
and
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.org
RewriteRule ^(.*) http://www.mydomain.org/$1 [L,R=301]
I have also tried pretty much all of the examples in the other threads on this topic.
Is there a possibility that we have a configuration problem somewhere?
Thanks,
TJ
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.domain\.com
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
So I would guess there's something else in htaccess that is conflicting with this (this is the first mod_rewrite that appears in htaccess).
I'll have to see if I can widgetise my entire htaccess and perhaps post it up.
Alternatively, could this error be caused by a misconfigured Apache?
Thanks,
TJ
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org [NC]
RewriteRule (.*) http://www.mydomain.org/$1 [R=301,L]
Have you looked at your logs to see if there is any indication there as to what the problem may be? Is it something like browser cache, cloaking software (no HOST header), or a browser that does not send HOST headers?
For Reference:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org [NC]
RewriteRule (.*) http://www.mydomain.org/$1 [R=301,L]
Will cause an HTTP 1.0 client, which does not send HOST headers to create an infinite loop, so by using:
RewriteCond %{HTTP_HOST} .
Which checks for any single character in the HOST param., the loop is broken.
Hope this helps.
Justin
[edited by: jd01 at 1:08 pm (utc) on July 11, 2005]
I am only posting to ask: why not use the non-www?
More out of curiosity than anything, because it seems people defer to the www. version more often than the non-www and I am wondering why...
Sorry, I can't be of more help.
Justin
According to the logs, the non-www URL is ending up at Apache's "default" (requests without a known server name).
This will need to be fixed in httpd.conf (ie. by the hosting company if it is a shared server). It might be neccessary to add a ServerAlias to the virtual host container:
<VirtualHost *>
DocumentRoot "/home/user/public_html"
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
OK, even with the alias to the non-WWW version (opposite of what you put in encyclo - maybe that's a problem?) it's not working.
vhost entry:-
<VirtualHost MY IP ADDY :80>
php_value sendmail_from info@example.org
ServerName www.example.org
ServerAlias example.org
ServerAdmin info@example.org
DocumentRoot /home/example/www
ErrorLog /home/example/logs/error.log
CustomLog /home/example/logs/access.log combined
<Directory /home/example/www>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
This is what is in the Apache config:-
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/var/www/html"
DocumentRoot "/home/<where it is landing currently>/www"
Should the vhost setting with alias override that?
Thanks,
TJ
We need jdMorgan here, I'm getting waaay out of my depth! ;)
I'm wondering if there is a conflict between your virtual host and the default defined virtual host.
My thoughts exactly, but I thought (assumed) that the vhost entry/alias would override anything else?
Another possibility is a DNS misconfiguration.
Both the www and non-www point to the same IP.
Are you using all IP-based or name-based virtual hosts?
All IP based.
Do you have a default-only virtual host?
Yes, the first entry in the vhost file is our default and that points to exactly where the non-www URL is now going. So it seems that the subsequent vhost alias is being ignored and the default is being used instead.
TJ