我有以下虚拟主机文件:
<IfModule !wsgi_module> LoadModule wsgi_module modules/mod_wsgi.so WSGISocketPrefix run/wsgi </IfModule> <VirtualHost *:80> RewriteEngine On RewriteLog "/var/log/httpd/rewrite_log" RewriteLogLevel 1 RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L] </VirtualHost> <VirtualHost *:443> ServerName https://tendril-api.dev.adnxs.net ServerAlias 06.tendril-api.dev.nym2.adnexus.net/api RewriteEngine on RewriteRule ^docs$ docs/ [R] ... # SSL & WSGI Setup </VirtualHost>
出于某种原因,我的docs重写规则根本没有生效。 为什么是这样? 我的HTTP – > HTTPS重写规则在*:80 VirtualHost中正常工作。 我正在做一些非常相似的事情。
这是否与在不同的VirtualHosts中有两个不同的重写规则有关?
有任何想法吗?
按照http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule:-
什么是匹配?
在VirtualHost上下文中,模式最初将与主机名和端口之后以及查询string(例如“/app1/index.html”)之前的URL部分相匹配。
您的模式与“文档”的确切url匹配。 实际的URL可能是“/ docs”,所以在“^”之后加上“/”可能会起作用: –
RewriteRule ^/docs$ docs/ [R]