我使用以下 .htaccess 代码在网站中启用友好 URL。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
代码工作正常,但有一个小异常(exception)。当我在浏览器中请求一个文件(即图像)时,浏览器会加载它(如我所料),但同时会执行 index.php。
我想知道为什么。
最佳答案
事实证明,浏览器正在发出 GET/favicon.ico
请求,因为根据 .htaccess
中的规则,服务器上没有具有该名称的文件> 文件,请求被重定向到 /index.php
。
关于php - 对现有文件的请求执行 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683705/