【问题标题】:Mod-rewrite shenanigansMod重写恶作剧
【发布时间】:2010-09-23 19:11:48
【问题描述】:

我有这个重写规则

RewriteEngine On
RewriteBase /location/
RewriteRule ^(.+)/?$ index.php?franchise=$1

假设要更改此 URL

http://example.com/location/kings-lynn

进入这个

http://example.com/location/index.php?franchise=kings-lynn

但是我得到了这个

http://example.com/location/index.php?franchise=index.php

另外,添加栏杆斜线会破坏它。我得到了 index.php 页面,但没有加载任何样式表或 javascript。

我显然做错了什么,但我不知道是什么,尽管我花了一整天的时间在 R'ingTFM 和许多在线入门、教程和问题上。

【问题讨论】:

标签: mod-rewrite


【解决方案1】:

你的问题是你重定向了两次。

'location/index.php' 匹配正则表达式 ^(.+)/?$

您可能希望使用“如果文件不存在”条件使其不再尝试映射。

RewriteEngine on
RewriteBase /location/
RewriteCond %{REQUEST_FILENAME} !-f   # ignore existing files
RewriteCond %{REQUEST_FILENAME} !-d   # ignore existing directories
RewriteRule ^(.+)/?$ index.php?franchise=$1  [L,QSA]

此外,还有 [L,QSA] 试图使其成为“最后”规则(注意,它的工作原理并不完全清楚)并将查询字符串附加到查询中,以便

location/foobar/?baz=quux  ==> index.php?franchise=$1&baz=quux

(我认为)

【讨论】:

    【解决方案2】:

    听起来好像重写过滤器执行了两次。尝试添加最后一个标志

    RewriteRule ^(.+)/?$ index.php?franchise=$1 [L]
    

    【讨论】:

      【解决方案3】:

      您的规则自匹配,因此它将引用自己。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-31
        • 1970-01-01
        • 2011-10-09
        • 2015-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-30
        相关资源
        最近更新 更多