views:

32

answers:

1

I have some conditions and rules in my .htaccess:

RewriteCond %{DOCUMENT_ROOT}/assets/img$1/.$2.$4/$3.$4 -f
RewriteRule ^assets/img(.*)/[a-zA-Z0-9-_\.]*\.[^/]+\.[a-z]{2,4}$ assets/img$1/.$2.$4/$3.$4 [NC]
RewriteRule ^assets/img(.*)/[a-zA-Z0-9-_\.]*\.[^/]+\.[a-z]{2,4}$ assets/img/image.php?path=$1&file=$2.$4&template=$3 [NC,L,QSA]

The regex is correct (tested and it matches, also in this .htaccess [1]). The variables $1, $2, $3 and $4 are nevertheless empty. And I am not sure why they are.

Some time ago I enabled each site with its own vhost config in /etc/apache2/sites-available/, but after a while I automated it with a ServerAlias and VirtualDocumentRoot:

ServerAlias *.localhost
VirtualDocumentRoot "/var/www/%1/public"

This autmatically mapped subdomain.localhost to /var/www/subdomain/public. Also, I needed to adjust my .htaccess. I had to insert a RewriteBase

RewriteBase /

This caused (I think) my RewriteRules did not work anymore. Is this true? And if so, how can I change these to work again?


PS [1] I verified this by using this RewriteRule:

RewriteRule ^assets/img(.*)/[a-zA-Z0-9-_\.]*\.[^/]+\.[a-z]{2,4}$ script.php?1=$1&2=$2&3=$3&4=$4 [L]

When you check the parameters in the script ($_GET) their keys exist in $_GET but they all contain empty strings.

A: 

I solved my own problem. In case others stumble upon this question, here is the answer.

Stupid enough I removed the parentheses in the regex. By changing this:

[a-zA-Z0-9-_\.]*

into this:

([a-zA-Z0-9-_\.]*)

it works again!

Jurian Sluiman