[prev in list] [next in list] [prev in thread] [next in thread]
List: apache-httpd-users
Subject: [users@httpd] Mod_Rewrite and Virtual Hosting.
From: Steve Redlich <apache () redlicheng ! com>
Date: 2005-01-29 19:31:22
Message-ID: Pine.LNX.4.58.0501291123530.27545 () steveredlich ! com
[Download RAW message or body]
Hi,
I've been using mod_vhost_alias successfully with
VirtualDocumentRoot /var/httpd/websites/%-2.0.%-1.0
However, I want to switch to using a "separate virtual host configuration file"
using mod_rewrite as described at the bottom of
http://httpd.apache.org/docs/vhosts/mass.html
The vhost map shown:
www.customer-1.com /www/customers/1
www.customer-2.com /www/customers/2
...
I want to make the "www." part of the URL optional.
I've setup my vhost map (and document directories) as shown:
domain1.com /var/httpd/user1/domain1.com
domain2.net /var/httpd/user1/domain2.net
domain3.com /var/httpd/user2/domain3.com
domain4.org /var/httpd/user2/domain4.org
doamin5.com /var/httpd/user3/domain5.com
...
I want to modify the rules in the given example to remove the
www. if present from the SERVER_HOST before looking up the
root directory (for the given domain) in the map
unlike the example, I have one cgi-bin directory on my server so I do not
need to map it per domain.
Below is my attempt at writing the modified configuration (in httpd.conf)
I would appreciate some comments on my modifications before trying it out
as I'm new to mod_rewrite.
Thanks,
Steve
--
RewriteEngine on
RewriteMap lowercase int:tolower
# define the map file
RewriteMap vhost txt:/etc/apache/vhost.map
# deal with aliases as in example
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
# handle leading www separately
RewriteCond ${lowercase:%{SERVER_NAME}} !^www\.
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1
# remove the www
RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1
--
Here is the original recipe from http://httpd.apache.org/docs/vhosts/mass.html
RewriteEngine on
RewriteMap lowercase int:tolower
# define the map file
RewriteMap vhost txt:/www/conf/vhost.map
# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/docs/$1
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic