【发布时间】:2015-08-04 01:36:57
【问题描述】:
假设
将所有内容重定向到 index.php,除了 Images 文件夹(如果文件存在)。 例如:
/main/test => index.php?controller=main&action=test
/image/exists.png => image/exists.png
/image/another.png => index?controller=image&action=another.png
当前代码
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks
RewriteCond "%{REQUEST_FILENAME}" "!-f"
RewriteRule ^image/(.*)$ index.php?controller=$1&action=$2 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/.*$ index.php?controller=$1&action=$2&v1=$3&v2=$4 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?controller=$1&action=$2&v1=$3&v2=$4 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ index.php?controller=$1&action=$2&v1=$3&v2=$4 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/$ index.php?controller=$1&action=$2&v1=$3 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)$ index.php?controller=$1&action=$2&v1=$3 [NC,L]
RewriteRule ^(.*)/(.*)/$ index.php?controller=$1&action=$2 [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?controller=$1&action=$2 [NC,L]
RewriteRule ^(.*)/$ index.php?controller=$1 [NC,L]
RewriteRule ^(.*)$ index.php?controller=$1 [NC,L]
</IfModule>
不良反应及请帮忙的原因
如果我将路径放入现有文件夹,您将被重定向到一个非常奇怪的路径。例如,如果我在浏览器中编写类似 localhost/image 的 URL,我会得到类似 localhost/image/?controller=Image 的 URL。最后 - 它加载了一个很好的文件,但看起来很丑。
/image => index.php?controller=image(但在浏览器的 URL 字段中:/image/?controller=Image)
PS 如果我使用 Firefox,我可以在没有 Query 的情况下获得很好的 URI。我认为这是因为 Firefox 在 URL 末尾添加了一个斜杠而没有扩展名。
如何“修复”它?
【问题讨论】:
标签: apache .htaccess mod-rewrite