[users@httpd] Dynamic RewriteRule based on the URL

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

 



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@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux