具有2个查询参数的URL所需的RewriteRule

时间:2014-09-26 14:51:02

标签: regex apache .htaccess mod-rewrite rewrite

theyouthtalent.com/user_wall.php?User=khalidmirza&Talent=Business

我想重写和重定向上面提到的网址,如

http://theyouthtalent.com/Business/khalidmirza

其中Business>>人才=商业和khalidmirza>>用户= khalidmirza

现在我正在使用这些以下的精神规则     http://theyouthtalent.com/khalidmirza

但我想在用户(khalidmirza)之前加入Talent(Business)

请提出改变以下规则以获得欲望结果。

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)$ user_wall.php?User=$1&Talent=$2 [L]
RewriteCond %{THE_REQUEST} user_wall\.php
RewriteCond %{QUERY_STRING} User=(\w+)&Talent=(\w+)
RewriteRule ^user_wall\.php$ /%1? [R=301,L]

1 个答案:

答案 0 :(得分:0)

在重写规则中,捕获2个组件的正则表达式是不正确的:

RewriteEngine On

RewriteCond %{THE_REQUEST} /user_wall\.php [NC]
RewriteCond %{QUERY_STRING} ^User=(\w+)&Talent=(\w+)$ [NC]
RewriteRule ^user_wall\.php$ /%2/%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/(\w+)/?$ user_wall.php?User=$2&Talent=$1 [L,QSA]