【发布时间】:2014-03-31 13:50:15
【问题描述】:
我在重写时遇到问题。 这是我的 .htaccess 文件
RewriteEngine On
RewriteBase /
#ignore non-existent utility-files
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|s?html|css|js|cgi|png|ico|txt)$
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* - [L]
#load existent utility files and don't rewrite them to index.php
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|s?html|css|js|cgi|png|ico|txt)$
RewriteRule ^(.*) $1 [L]
#load other files if they exist
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
#load index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
最后一部分正在工作,但我想避免在代码请求不存在的图像时加载我的 index.php(如:www.mysite.test/images/foobar.png)
第一个 RewriteCond-Line 应该检查请求是否匹配图像、JavaScript 等文件,第二个 RewriteCond 行应该检查该文件是否不存在。 第三个应该检查文件夹是否存在。 如果匹配成功,则不应加载任何内容。
它有效,但前提是该文件夹存在。如果图像不存在的文件夹则不起作用。
【问题讨论】:
标签: apache file .htaccess mod-rewrite