【发布时间】:2016-03-21 06:41:09
【问题描述】:
我一直在尝试将 png 和 jpg 文件排除在重写条件之外。目前,我有一组图片被显示为损坏的图像。导致错误的原因是我的 .htaccess 中的重写规则。该规则会覆盖文件夹的 URL,因此它将在 URL 中显示为不同的名称,而不是 /volley,它显示为 JeepVolleyballChampionship。如果目录不存在,我试图摆脱重定向到主页的最后一部分,但似乎没有任何效果。我还尝试从重写目录的重写块中排除扩展名为 png 和 jpg 的文件...
我假设我没有正确实施该排除。我的页面仍然可以正常加载,除了损坏的图像。您能否提供有关我在此块中做错了什么的见解?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^JeepVolleyballChampionship(.*)$ /volley [L,QSA]
</IfModule>
这里提供了我的整个 .htaccess:
#the non-existent JeepVolleyballChampionship folder leads to the volley folder without showing it or the extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
DirectorySlash Off
RewriteEngine on
#try to make it so that /volley/ is eliminated from folders and name changes but it is still under this structure
RewriteRule ^volley$ /volley/index.php [L,E=LOOP:1]
RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^volley/$ /volley [R=301,L]
RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^volley/index.php$ /volley [R=301,L]
#the non-existent JeepVolleyballChampionship folder leads to the volley folder without showing it or the extension
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^JeepVolleyballChampionship(.*)$ /volley [L,QSA]
</IfModule>
#non-existent folder to default root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
</IfModule>
【问题讨论】:
标签: php apache .htaccess mod-rewrite url-rewriting