当请求包含具有相对路径的文件/图像的页面时,应用程序将针对每个请求运行。因此,应用程序已自动启动并执行多次。
当图像在文件名中有下划线
时,似乎会出现问题<img src="assets/images/_download.jpg" alt="test">
<img src="assets/images/_downlaod2.jpg" alt="test">
<img src="assets/images/_downlod3.jpg" alt="test">
我注意到了这一点,因为我正在使用Xdebug。我想知道如何防止这种情况以及最佳做法是什么?
的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
# absolute physical path to the directory that contains this htaccess file.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
答案 0 :(得分:1)
您缺少文件夹条件:
RewriteCond %{REQUEST_FILENAME} !-d
在请求解析为文件夹的情况下,它会阻止重写。因此,根据您的htaccess
代码,所有请求都将被重写为index.php
文件,但解析为文件的请求除外。由于您的图像位于文件夹中,因此它们首先解析为文件夹。
您的重写应如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]