Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite sub domain question

Status
Not open for further replies.
Another way would be to use apache's ErrorDocument directive. Check to make sure there isn't one already. If there is, simply edit it to something like this:

Code:
ErrorDocument 404 /path/to/new-location.html

There will need to be some content on this page or IE may ignore it and display its own default error page.

 
That catches every 404 so if a user is in valid subdomain2 and looks for a non existent page then they would end up at the same page as a user that went to a non existent domain.

Martin Trew
 
That's true but I thought it went without saying that you would have to set the scope for that directive. In a case like yours you could create a <Location> or <LocationMatch> container and use the ErrorDocument directive within that. Apache will also use the first vhost defined if it doesn't find a match for the requested domain (ServerName). If you are hosting one domain then that may be an option. Forgive me for coming up with so many hoakie solutions but I'm assuming that you are trying to avoid using mod_rewrite.

 
THanks for taking the time :)

here is my httpd-vhosts.conf but unfortunately it doesn't default to the first vhost as I expected :(

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:800

#
# get the server name from the Host: header
UseCanonicalName Off

<VirtualHost *:800>
# ServerAdmin webmaster@eazi.it
DocumentRoot "d:/websites/new.eazi.it"
</VirtualHost>

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog "|bin/rotatelogs -l logs/access.%Y.%m.%d.log 86400" vcommon
Errorlog "|bin rotatelogs -l logs/error.%Y.%m.%d.log 86400"
ErrorDocument 404 /404.php

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot "d:/websites/%1+/"





Martin Trew
 

The problem is that you don't want to enumerate the sites
in your config file. In your example, you would need a vhost for every good site after the "default", which defeats the purpose of the VirtualDocumentRoot. Not to day that could not be done, and you would rewrite the default to your "new" site.

You could use a length RewriteCond but once again it is a line per site.

I think what should work (I have not done this) is a rewrite map, so you would
enumerate the sites in a simple map file. Read the example
rewrite rules on apache.org for the rewrite maps. The example is much more complicated than you need. I think in their sample, server0 is your "new" site.

eugene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top