RewriteRule slash optional

烈酒焚心 提交于 2019-12-24 00:08:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!