简体   繁体   English

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

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

I have already looked through SO and came up with this code, which i think should work, but it does not: 我已经看过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]

Basically everything should be rewritten except for: favicon.png robots.txt everything inside the directory "static" 基本上,所有内容都应重写,除了:favicon.png robots.txt目录“ static”中的所有内容

Part of it works. 部分有效。 favicon.png returns the favicon.png file instead of rewriting to index.php. favicon.png返回favicon.png文件,而不是重写为index.php。 Content inside of "static" is not rewritten as well. “静态”内部的内容也不会被重写。 But robots.txt and sitemap.xml do not work. 但是robots.txt和sitemap.xml无法正常工作。 I have no idea why. 我不知道为什么。 Can anyone help? 有人可以帮忙吗?

You can combine all of them into single and more correct rule. 您可以将它们全部组合成单个更正确的规则。 Try this code: 试试这个代码:

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