现在我有指示:
www.website.com/user.php?u=peter
或
www.website.com/userhome.php?u=peter
我想将它们缩短为
www.website.com/user/peter
www.website.com/userhome/peter
这是我现在的代码,它不起作用。当我输入website.com/user/peter时,网站会给我一个我自己的错误,好像它不能获取用户名。 "该用户不存在或尚未激活,请按"
# Turn Rewrite Engine On
RewriteEngine on
# NC make the rule non case sensitive
# L make this the last rule that this specific condition will match
# $ in the regular expression makes the matching stop
# Rewrite for user.php?u=xxxxx
RewriteRule ^user/([0-9a-zA-Z]+) user.php?u=$1 [NC,L]
# Rewrite for userhome.php?u=xxxxx
RewriteRule ^userhome/([0-9a-zA-Z]+) userhome.php?u=$1 [NC,L]
答案 0 :(得分:1)
尝试使用以下规则:
#To leave the URL www.example.com/user/peter
RewriteRule ^user/([^/]*)$ /user.php?u=$1 [L]
#To leave the URL www.example.com/userhome/peter
RewriteRule ^userhome/([^/]*)$ /userhome.php?u=$1 [L]
确保在测试之前清除缓存。