简体   繁体   English

特定格式的URL重写规则

[英]URL Rewrite Rules in specific format

I have written a .htaccess file for URL to rewrite but it has some error due to which does't give desired output, need some expert opinion/result to get it right. 我为URL编写了一个.htaccess文件以进行重写,但是由于它无法提供所需的输出而导致了一些错误,需要一些专家的意见/结果才能正确进行。

Here is URL I want to rewrite 这是我要重写的URL

http://theyouthtalent.com/user-wall.php?User=dillagiary&Talent=TV

should be rewrite to 应该重写为

http://theyouthtalent.com/TV/dillagiary

and my existing .htaccess file has following lines 我现有的.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]

Important point is I want to Talent value first and then username 重要的一点是,我想先选拔人才,然后再选择用户名

 http://theyouthtalent.com/user-wall.php?User=dillagiary&Talent=TV 

The Talent query string parameter value contains a dot ( . ), but the shorthand character class \\w (word characters) does not include a dot. Talent查询字符串参数值包含一个点( . ),但是速记字符类\\w (单词字符)不包含一个点。 So, you need to include a dot in the pattern. 因此,您需要在模式中包含一个点。 ie. 即。 Change the relevant (\\w+) pattern to ([\\w.]+) . 将相关的(\\w+)模式更改为([\\w.]+)

Also, the request URL contains a hyphen ( - ), not an underscore ( _ ). 此外,请求URL包含连字符( - ),而不包含下划线( _ )。

For example: 例如:

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]

The \\w character class by itself is equivalent to: [A-Za-z0-9_] \\w字符类本身等效于: [A-Za-z0-9_]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM