[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Apache (was Apace) Redirect Question

> Here are the settings for one of my multisite servers.

Good afternoon Wolf,

I am afraid I am not accomplishing what I want to do with your information
either. I've tried to get it to work with my layout, but no matter what
I do, entering http://domain1.com in the client's browser either gives
me a 404 if there is nothing explictely defined to serve a request for
http://domain1.com, or if I define a server alias, then the URL never changes
to http://www.domain1.com, but the page is served. This is basically what
I had with my site definitions too.

I did find some old documentation on the Apache site that seems to support
exactly what I want to do, but I am unable to make it work either. Granted
this is for version 2.0, but the regular expressions should be valid. That URL
is http://httpd.apache.org/docs/2.0/misc/rewriteguide.html. The description
under the section labeled Canonical Hostnames reads:

"The goal of this rule is to force the use of a particular hostname,
in preference to other hostnames which may be used to reach the same
site. For example, if you wish to force the use of www.example.com instead
of example.com, you might use a variant of the following recipe."

The rewrite rules listed for that recipe are:
   RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
   RewriteCond %{HTTP_HOST}   !^$
   RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]

I have placed these rules as global directives in /etc/apache2/apache2.conf,
and they did not work. I tried them in the default site file, and in the
vhost definition for domain1.com. Again, unless I have a line in the file
sites-avaliable/domain1.com that reads "ServerAlias domain1.com", the request
for http://domain1.com results in a 404 error. If I place the ServerAlias
line in the file, the page is served, but URL is never rewritten. I have even
created a LogFormat template that captures the host request, and domain1.com
is what is being requested.

It is almost as if the rewrite engine is never made aware of the fact that
the condition it is supposed to be looking for has in fact occurred. I find
it hard to beleive this is a bug that has gone unnoticed for this long, so
I've got to believe it is something I've done wrong. But I have followed the
example exactly as written, and I am familar enough with regular expressions
to know that !^www\.domain1\.com [NC] means a host that does not start with
www.domain1.com, ignoring letter case, and that !^$ means the host request is
not empty. So why does a request for domain1.com, which meets both criteria,
not trigger the rewrite rule?

At this point I am utterly frustrated because the documentation is clear,
but following it fails. I just want to type http://domain1.com into the
address bar, and have Apache change it to http://www.domain1.com. I just do
not know how to accomplish this.

Sent - Gtek Web Mail

Reply to: