mercredi 29 juillet 2015

Apache (httpd) VirtualHost RewriteCond Variables not working

I am trying to make a dynamic virtual host entry with the intent of redirecting all traffic to .mydomain.com to /var/www/html/ this part works but I also what a Rewrite conditions that checks if the directory exists if it does not then I want to redirect all traffic to the root /var/www/html/index.php.

This part is not working because the during my testing I noticed that none of the Rewrite variables are working they are are blank and I cannot figure out why here is my virtual host configuration

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

# this log format can be split per-virtual-host based on the first field
# LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    VirtualDocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
    ServerName vhosts.mydomain.com
    ServerAlias *
    VirtualDocumentRoot /var/www/html/%1

    RewriteEngine on
    LogLevel warn rewrite:trace4

    # If the request is not for a valid directory
    RewriteCond /var/www/html/%1 !-d
    RewriteCond %{REQUEST_FILENAME} !-d
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the request is not for a valid link
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* /var/www/html/index.php

</VirtualHost>

You will notice that I have several uses of the variable that I can use when testing and looking at my log file this

[Wed Jul 29 16:56:56.015818 2015] [rewrite:trace2] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [http://ift.tt/1KzVejt] init rewrite engine with requested uri /
[Wed Jul 29 16:56:56.016050 2015] [rewrite:trace3] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [http://ift.tt/1KzVejt] applying pattern '.*' to uri '/'
[Wed Jul 29 16:56:56.018361 2015] [rewrite:trace4] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [http://ift.tt/1KzVejt] RewriteCond: input='/var/www/html/' pattern='!-d' => not-matched
[Wed Jul 29 16:56:56.018411 2015] [rewrite:trace1] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [http://ift.tt/1KzVejt] pass through /

even though %1 passes for the virtual directory just fine it does not work in the mod rewrite rule. All other uses of the variables yield the same results any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire