.htaccess:用params重写url不会工作

时间:2014-04-20 15:26:06

标签: .htaccess mod-rewrite url-rewriting

这是我的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

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

  

/简档/史蒂夫

  ?

的index.php P =型材&安培;用户=史蒂夫

现在当我到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]

(感谢Jon Lin) 但现在我把它作为输出:(print_r($ _ GET);):

Array ( [p] => profiles/Steve )

我想:

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

修正了,规则大多数是在另一个重写之前。

1 个答案:

答案 0 :(得分:0)

您正在创建分组"个人资料",您只需要路径的第二部分:

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