You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Norman Khine <no...@khine.net> on 2006/09/06 09:23:27 UTC
[users@httpd] Dynamic RewriteRule based on the URL
Hello,
Is it possible to create an Apache Rewrite rule so that the depending on
the sub-domain the server receives it is then re-written to a different
folder, for example, I have this working but want to reduce it to just
one rule:
<VirtualHost *:80>
ServerName folder_A.domain.tld
RewriteEngine On
RewriteRule ^/(.*) http://localhost:9080/folder_A/$1 [P]
RequestHeader set X-Base-Path folder_A
ErrorLog /var/log/apache2/folder_A-error_log
CustomLog /var/log/apache2/folder_A-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName folder_B.domain.tld
RewriteEngine On
RewriteRule ^/(.*) http://localhost:9080/folder_B/$1 [P]
RequestHeader set X-Base-Path folder_B
ErrorLog /var/log/apache2/folder_B-error_log
CustomLog /var/log/apache2/folder_B-access_log common
</VirtualHost>
etc...
So is there a nice way to reduce this to only one rule where if a
request is sent to folder_A.domain.tld the RewriteRule, RequestHandler,
ErrorLog, CustomLog entries are changed accordingly?
Perhaps something like in the line of %{SERVER_NAME}:
<VirtualHost *:80>
ServerName %{FOLDER_NAME}.domain.tld
RewriteEngine On
RewriteRule ^/(.*) http://localhost:9080/%{FOLDER_NAME}/$1 [P]
RequestHeader set X-Base-Path %{FOLDER_NAME}
ErrorLog /var/log/apache2/%{FOLDER_NAME}-error_log
CustomLog /var/log/apache2/%{FOLDER_NAME}-access_log common
</VirtualHost>
Would this work and how would you set the %{FOLDER_NAME} if it does or is there a different approach?
Many thanks
Norman
---------------------------------------------------------------------
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