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

[SOLVED] Re: Apache Redirect Question



> did you link the sites in sites-available to sites-enabled?
> 
> Wolf Halton
> http://sourcefreedom.com

>> >
>> > in domain1.com vhost config:
>> >
>> > redirect permanent / http://www.domain1.com/
>> >
>> > source:
>> >       http://httpd.apache.org/docs/2.2/en/mod/mod_alias.html#redirect

Good morning Mouss and Wolf,

I have managed to accomplish my goal, and it was with help from both of
you. Mouss, your tip is almost correct if I make two changes, and Wolf,
your question started this line of thought for me.

I copied my existing sites-available/domain1.com to
sites-available/www.domain1.com, ran a2ensite www.domain1.com, then modified
sites-available/domain1.com. It points the DocumentRoot to /var/www, same as
sites-available/default. There is no index.html in that directory. I then
added:
   RedirectMatch "/(.*)" "http://www.domain1.com/$1";
What this does is take any request for domain1.com, with any additional
paths, and redirects the request to http://www.domain1.com, with any
additional paths from the first request appended to the URL (I think that's
the correct terminology).

So now if the user request is just the server's IP address, the default site
returns the 404 ErrorDoc. If the request is for http://domain2.com, the same
is returned. If the request is for http://www.domain2.com,
/var/www/htdocs/domain2.com/index.html is returned.

If the request is for http://domain1.com, it is redirected to http://www.domain1.com, with that URL then appearing in the address bar as
I wanted. Finally, all requests for http://www.domain1.com return
/var/www/htdocs/domain1.com/index.html.

In the end, I have five sites in sites-available, with four of them linked
from sites-enabled: default; default-ssl; domain1.com; domain2.com;
www.domain1.com

Common sense dictates that I rename my /var/www directories to
/var/www/htdocs/www.domainX.com, and sites-available/domain2.com to
sites-available/www.domain2.com so I can maintain the name to site mapping
in my mind.

The contents of sites-available/domain1.com
<VirtualHost *:80>
   ServerAdmin  webmaster@domain1.com
   ServerName   domain1.com
   DocumentRoot /var/www/
   RedirectMatch "/(.*)"      "http://www.domain1.com/$1";

   <Directory />
      Options       FollowSymLinks
      AllowOverride None
   </Directory>

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel   warn
   ErrorLog  ${APACHE_LOG_DIR}/domain1.com/error.log
#   CustomLog ${APACHE_LOG_DIR}/domain1.com/access.log mydebug
   CustomLog ${APACHE_LOG_DIR}/domain1.com/access.log combined
</VirtualHost>


Sent - Gtek Web Mail



Reply to: