Exception with .htaccess (image broken)

感情迁移 提交于 2020-01-23 17:40:20

问题


I'm using:

RewriteRule ^(.*)$ index.php?abrir=$1
RewriteRule ^(.*)/(.*)/(.*)$ index.php?abrir=$1&id=$2&pagina=$3

and I have the image link:

/data_livro/capa_livro/af58e898f91509b.jpg

How I can add a exception for show the image? Its broke...

My full .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)$ index.php?abrir=$1
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?abrir=$1&id=$2&pagina=$3

RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

ErrorDocument 400 index.php
ErrorDocument 401 index.php
ErrorDocument 403 index.php
ErrorDocument 404 index.php
ErrorDocument 504 index.php
ErrorDocument 505 index.php
DirectoryIndex index.php

回答1:


I find that using .* in a rewrite rule is too general. I tend to use more specific character classes:

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?abrir=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?abrir=$1&id=$2&pagina=$3

This doesn't rewrite any request with a dot in it, so specific file names (/styles/my.css, /images/example.jpg) get ignored. Also, I like to add /? to allow an optional trailing slash, but that's a personal preference :-).




回答2:


If I'm understanding this correctly, ading the following ahead of your RewriteRules should solve the problem:

RewriteCond %{REQUEST_FILENAME} !-f

However, I'd also suggest modifying your RewriteRules to look like:

RewriteRule ^([^/]+)$ index.php?abrir=$1
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?abrir=$1&id=$2&pagina=$3


来源:https://stackoverflow.com/questions/7841616/exception-with-htaccess-image-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!