当url以斜杠结尾时,htaccess重写器返回不正确的参数


htaccess rewriterule returns incorrect parameter when the url ends with slash

我有点困惑,为什么当url以斜杠结尾时,它会返回不正确的参数。

htaccess

RewriteRule ^account/dashboard/(.*)/(.*)$ ./account/index.php?page=dashboard&aid=$1&name=$2 [L,QSA] 

当我执行http://example.com/account/dashboard/65/blitzen12/

在页面中,我可以使用$_GET['aid],它返回65/blitzen12$_GET['name]返回空

但当我删除url中blitzen12末尾的斜杠时,它会正确返回65blitzen12

有人能向我解释一下我做错了什么吗?

您应该这样做:

RewriteRule ^account/dashboard/([^/]+)/([^/]+)/?$ ./account/index.php?page=dashboard&aid=$1&name=$2 [L,QSA]

这与贪婪的重复有关。基本上,点匹配任何字符,包括斜线(/)