由网友(易烊千玺的小娇妻)分享简介:我刚刚开始学习正规的前pressions,我实在不明白这一点。我需要强制斜线的URL末尾,如果它不包含扩展名。I just started learning regular expressions and I just can't figure this out. I need to force a slash at...
我刚刚开始学习正规的前pressions,我实在不明白这一点。我需要强制斜线的URL末尾,如果它不包含扩展名。
I just started learning regular expressions and I just can't figure this out. I need to force a slash at the end of an URL if it not contains an extensions.
因此,为了更清楚:
So to be more clear:
example.com/test/ stays the same.
example.com/test.php stays the same.
example.com/test becomes example.com/test/ (See the last slash at the end)
任何谁知道如何解决这个问题?
Anyone who knows how to fix this?
推荐答案
自叹不如我刚刚发现意外的解决方案:
Strange enough I just found a solution by accident:
RewriteCond %{REQUEST_URI} /+[^.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
首先,添加在每行的末尾斜线,即使它与.PHP结束,但现在它的作品,奇怪的是。
At first it added a slash at the end of every row, even which ended with .php but now it works, strangely enough.
相关推荐
最新文章