Mod_Rewrite help to understand this expression
RewriteRule ^user/(\w{1,50})\-\-(\w{1,50})\-(\w{1,50})\.html users.php?na开发者_Go百科me=$1 [L]
url looks like this
site.com/user/first-middle-last.html
for some reason variable $_GET['name'] inside users.php returns only first name part not entire first middle and last, how can i make it process full name into name var
Your regex has 3 capturing groups:
^user/(\w{1,50})-(\w{1,50})-(\w{1,50})\.html
\________/ \________/ \________/
$1 $2 $3
$1
is the first group capturing: (\w{1,50})
. If you want the whole text, try:
RewriteRule ^user/(\w{1,50}-\w{1,50}-\w{1,50})\.html users.php?name=$1 [L]
\__________________________/
$1
In addition, note that you don't have to escape dashes (-
) outside of character set ([...]
), and you have two dashes between the first and second word.
If you need, you can have it both ways - capture each word and the whole name:
^user/((\w{1,50})-(\w{1,50})-(\w{1,50}))\.html
|\________/ \________/ \________/|
| $2 $3 $4 |
\________________________________/
$1
Each $n
references a parenthesized group. In this case, $1
represents the first (\w{1,50})
; the rest is being trapped into $2
and $3
. Assuming the double hyphen is in fact supposed to be mapped to a single one (this is not clear from your example), you probably want
RewriteRule ^user/(\w{1,50})\-\-(\w{1,50})\-(\w{1,50})\.html users.php?name=$1-$2-$3 [L]
If that was a mistake and you do want the entire first--middle-last
expression being rewritten, then @Kobi's answer is more correct than cutting it up and re-joining.
精彩评论