繁体   English   中英

htaccess:mod_rewrite(某些文件的例外)

[英]Htaccess: mod_rewrite (exceptions for certain files)

我已经看过SO了,并想出了这段代码,我认为应该可以,但是没有:

RewriteEngine On
RewriteRule favicon.png - [NC]
RewriteRule robots.txt - [NC]
RewriteRule sitemap.xml - [NC]
RewriteRule ^static - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

基本上,所有内容都应重写,除了:favicon.png robots.txt目录“ static”中的所有内容

部分有效。 favicon.png返回favicon.png文件,而不是重写为index.php。 “静态”内部的内容也不会被重写。 但是robots.txt和sitemap.xml无法正常工作。 我不知道为什么。 有人可以帮忙吗?

您可以将它们全部组合成单个更正确的规则。 试试这个代码:

RewriteCond %{REQUEST_URI} !^/(favicon\.png|robots\.txt|sitemap\.xml|static/) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM