htaccess redirect only if it has value after forward slash

依然范特西╮ 提交于 2021-02-07 20:12:37

问题


I would like to apply the following htaccess rule only if there is a value after the forward slash of /events/

If I visit /events/ (Don't do anything. DO NOT apply the htaccess rule)

But if I visit /events/this-can be-anything/ (Apply the htaccess rule below)

RewriteRule ^events/(.*) /lp/events/index.php [L]

This is obviously not working.


回答1:


You need to change your regex pattern (.*) to (.+) to match at least one character after the uri.

RewriteRule ^events/(.+)$ /lp/events/index.php [L]


来源:https://stackoverflow.com/questions/44171636/htaccess-redirect-only-if-it-has-value-after-forward-slash

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