Forum Moderators: phranque

Message Too Old, No Replies

URL format.for a redirect in Apache

         

Montezuma45

6:48 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



In /etc/apache2/vhosts/00_default_vhost.conf, I have:

<VirtualHost *:80>
ServerName abc.com
ServerAlias *.abc.com abc.com
Redirect / http://www.abc.com
ServerAdmin admin@abc.com
DocumentRoot /var/www/abc.com
</VirtualHost>

It seems to me that there was an issue on putting '/' after the web name and I can't remember what it was. Was it suppose to be at the end or not?

Am I even in the right file? It's been a while.

Thanks.

[edited by: tedster at 7:51 pm (utc) on Feb 17, 2011]
[edit reason] moved from another location [/edit]

jdMorgan

2:22 am on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The slash should be there if you want a valid URL-path to redirect to. Also, you need to prevent a loop, either by using a separate VirtualHost for the non-canonical hostnames, or by using mod_rewrite so that you can test %{HTTP_HOST} and selectively redirect only non-canonical-hostname requests while not redirecting canonical ones (and thereby looping forever).

There's a duplication of your servername in your ServerAlias directive there, and technically, if you're going to redirect TO "www", the ServerName should be "www" and the ServerAlias should be "non-www" -- Saves *all kinds* of trouble if someone sets UseCanonicalName on by accident or malice...

The "leave the trailing slash off" thing applies to subdirectory URL-paths, and not to the delimiter after the hostname... And I can't remember where that note is either... mod_alias, maybe? The purpose is so that mod_dir can still work to "reclaim" the request if the client leaves off the trailing slash on a subdirectory-path. This is not a problem with the root directory as in this case here, though.

Jim

Montezuma45

4:15 am on Feb 18, 2011 (gmt 0)

10+ Year Member



Thanks.