【问题标题】:htaccess: multiple rewriterulehtaccess:多次重写
【发布时间】:2015-05-13 22:13:29
【问题描述】:

我想重写以下内容:

http://www.example.com/maphttp://www.example.com/index.php?p=map

http://www.example.com/map/1http://www.example.com/index.php?p=map&id=1

我当前的代码是:

RewriteEngine On
RewriteRule ^([^/]*)\$ /index.php?p=$1 [NC]
RewriteRule ^([^/]*)/([^/]*)\$ /index.php?p=$1&id=$2 [L]

但是如果失败了……

谁能帮助我获得正确的 .htaccess 代码?提前谢谢!

【问题讨论】:

  • 行尾匹配器不需要转义

标签: regex apache .htaccess mod-rewrite


【解决方案1】:

您需要在重写时忽略真实文件和目录,并且不要转义$

你可以使用:

RewriteEngine On

# rule to ignore files and directories from all rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

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

RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?p=$1&id=$2 [L,QSA]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 2017-03-11
    • 2012-10-03
    • 2012-10-29
    相关资源
    最近更新 更多