简体   繁体   中英

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.

Here is URL I want to rewrite

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

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. So, you need to include a dot in the pattern. ie. Change the relevant (\\w+) pattern to ([\\w.]+) .

Also, the request URL contains a hyphen ( - ), not an underscore ( _ ).

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_]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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