.htaccess 为什么mod_rewrite有时会在缺少尾部斜杠时执行外部重定向?
我使用以下重写规则:.htaccess 为什么mod_rewrite有时会在缺少尾部斜杠时执行外部重定向?,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我使用以下重写规则: RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI} -f [or] RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}/index.html -f [or] RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}index.html -f RewriteRule ^(.+) static/$1
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI} -f [or]
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}/index.html -f [or]
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}index.html -f
RewriteRule ^(.+) static/$1
它们都成功地为static
目录中的文件提供服务,而不需要在url中包含static/
。唯一的区别是,当我没有尾随斜杠时,static
目录会像外部重定向一样添加到URL中
因此,
-->
及
-->
但是,
-->
有没有一种方法可以使索引文件从
/static/products
目录中提供,而不会像其他两种情况那样在url中显示static
目录?我打赌有一种更简单的方法来实现这一点,但我最终想出了一个有效的组合:
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}index.html !-f
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}/index.html -f
RewriteRule ^(.+) static/$1/
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}index.html -f [or]
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI} -f
RewriteRule ^(.+) static/$1