使用链接 RewriteRule 中的 RewriteCond 检查文件是否存在
我希望你能在这里帮助我。
我有一个 RewriteRule,它根据域名为您提供一个 crossdomain.xml 文件。我以忽略“.dev”的方式拥有它。中间的字符串,例如:
Request: http://site1.dev.mydomain.com/crossdomain.xml
返回文件:/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]
问题:如何检查文件是否存在?我尝试将其添加到顶部,但它不起作用:
RewriteCond /etc/httpd/conf/crossdomain/$1.$2.xml -f
我想因为这是一个连锁规则,不知道。请帮忙。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,我刚刚找到了解决方法,我所做的不是终止重写并添加另一个重写,该重写仅在第一个应用时才起作用。它检查文件是否不存在,如果存在,则应用进一步重写:
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:
我认为这与链接的规则没有任何关系,您只是在与错误的值进行比较。
应该有效。
I don't think it has anything to do with the rule being chained, you're just comparing against the wrong value.
should work.