[英]URL Rewrite Rules in specific format
我为URL编写了一个.htaccess文件以进行重写,但是由于它无法提供所需的输出而导致了一些错误,需要一些专家的意见/结果才能正确进行。
这是我要重写的URL
http://theyouthtalent.com/user-wall.php?User=dillagiary&Talent=TV
应该重写为
http://theyouthtalent.com/TV/dillagiary
我现有的.htaccess文件有以下几行
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]
重要的一点是,我想先选拔人才,然后再选择用户名
http://theyouthtalent.com/user-wall.php?User=dillagiary&Talent=TV
Talent
查询字符串参数值包含一个点( .
),但是速记字符类\\w
(单词字符)不包含一个点。 因此,您需要在模式中包含一个点。 即。 将相关的(\\w+)
模式更改为([\\w.]+)
。
此外,请求URL包含连字符( -
),而不包含下划线( _
)。
例如:
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]
\\w
字符类本身等效于: [A-Za-z0-9_]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.