【发布时间】:2015-12-25 02:04:56
【问题描述】:
我当前的 .htaccess 文件可以工作,但我认为这不是解决这个问题的最佳方法,而且我担心它在未来有更多的重写规则时不会工作。
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^files/(.*) files/$1 [END]
RewriteRule ^(.*) files/$1 [END]
</IfModule>
服务器检查 url 是否指向“files”文件夹,只有在指向其他地方时才会重写。
我尝试了类似的东西
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule !^files/(.*) files/$1 [END]
</IfModule>
但它不起作用,因为我无法传递 $1 变量。我不想要这样的东西
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{URL_STARTING_AT_THIS_POINT} ^files/*
RewriteRule ^(.*) files/$1 [END]
</IfModule>
或
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !%{URL_TO_THIS_HTACCESS}/files/*
RewriteRule ^(.*) files/$1 [END]
</IfModule>
我没有为此找到任何服务器变量。我想比较 RewriteCond 中 RewriteRule (^files/) 的第一个参数,但没有找到正确的服务器变量。
【问题讨论】:
-
我有点困惑。你也想比较第一个参数。你不想发生什么?
-
例如网址是
www.myserver.com/path/to/htaccess/files/index.html。我的.htaccess位于文件夹 htaccess 中。所以此时RewriteRule的第一个参数是files/index.html。我想知道,如何在 RewriteCond 中使用这个参数(以文件夹 htaccess 开头的 URL)。
标签: apache .htaccess mod-rewrite