问题
When I put "?" after slash to make it optional, like this:
RewriteRule ^user/(.*)/?$ "/index.php?page=view-user&user=$1"
But now when I open URL with slash like /user/revolution/ in PHP, $_GET['user'] output "rloveution/" (with slash). So how can I make the trailing slash optional without getting username output with slash ?
Thanks.
回答1:
You can use negated regex:
RewriteRule ^user/([^/]+)/?$ index.php?page=view-user&user=$1 [L,QSA]
Or lazy matching:
RewriteRule ^user/(.+?)/?$ index.php?page=view-user&user=$1 [L,QSA]
来源:https://stackoverflow.com/questions/36848564/rewriterule-slash-optional