views:

364

answers:

2

Hello, I hope you could help me here.

I have a RewriteRule which gives you a crossdomain.xml file depending on the domain name. I have it in a way that ignores the ".dev." string in the middle, example:

Request: http://site1.dev.mydomain.com/crossdomain.xml
Returns file: /etc/httpd/conf/crossdomain/site.mydomain.com.xml

RewriteCond %{HTTP_HOST} "^(.*)\.dev\.(.*)"
RewriteCond %{REQUEST_URI} "/crossdomain.xml"
    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
    RewriteRule ^(.*)\.dev\.([^/]*)/crossdomain.xml /etc/httpd/conf/crossdomain/$1.$2.xml [L]

Question: How do I check if the file exists? I tried adding this on top but it doesn't work:

RewriteCond  /etc/httpd/conf/crossdomain/$1.$2.xml  -f

I guess because it is a chained rule, no idea. Please help.

A: 

I don't think it has anything to do with the rule being chained, you're just comparing against the wrong value.

RewriteCond %{REQUEST_FILENAME} -f

should work.

Pekka
Hi and thanks for your answer, that is a good try but I tried and it doesn't work, I don't know why.
gelilloabad
A: 

Right, I just found a way around it, what I do is not terminating the Rewrite and add another one which is meant to work only if the first applied. It checks if the file doesn't exists, if so it applies a further rewrite:

RewriteCond %{HTTP_HOST} "^(.*)\.dev\.(.*)"
RewriteCond %{REQUEST_URI} "/crossdomain.xml"
    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
    RewriteRule ^(.*)\.dev\.([^/]*)/crossdomain.xml /etc/httpd/conf/crossdomain/$1.$2.xml

RewriteCond /etc/httpd/conf/crossdomain/$1.xml !-f
        RewriteRule /etc/httpd/conf/crossdomain/(.*)\.xml /etc/httpd/conf/crossdomain/crossdomain-default.xml [L]
gelilloabad