【问题标题】:.htaccess: rewrite url with params wont work.htaccess:使用参数重写 url 不起作用
【发布时间】:2014-06-04 17:40:24
【问题描述】:

这是我的 htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/(lib|assets|index\.php) [NC]
RewriteRule ^/?$ index.php?p=index [L,QSA]

RewriteCond %{REQUEST_URI} !/(lib|assets|index\.php) [NC]
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]


RewriteRule ^(profiles\/\w+)$ index.php?p=profiles

关于最后一条规则,我想重写这个网址:

/profiles/史蒂夫

index.php?p=profiles&user=Steve

现在,当我进入 mysite/profiles/ 时,它会起作用,但现在我需要添加 &u=Steve,所以:

RewriteRule ^(profiles\/\w+)$ index.php?p=profiles&u=$1

当我访问 mysite/profiles/Steve 时

我会收到 404 错误。

为什么这不起作用以及如何解决?

编辑:

现在我有了这个:

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

(感谢乔恩·林) 但现在我有这个作为输出:(print_r($_GET);):

Array ( [p] => profiles/Steve )

我想要:

Array ( [p] => profiles [u] => Steve )

固定,规则最先于其他重写规则。

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您正在围绕“配置文件”创建分组,您只需要路径的第二部分:

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

    【讨论】:

    • @user3144435 不确定如何使用上述规则获得该结果,它对我来说很好。
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2014-08-08
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多