[英].htaccess if url not ends with extension, add slash at the end
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? 有谁知道如何解决这个问题?
Put this on your .htaccess : 把它放在你的.htaccess上:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^/test$ /test/ [L]
Strange enough I just found a solution by accident: 奇怪的是,我偶然发现了一个解决方案:
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
At first it added a slash at the end of every row, even which ended with .php but now it works, strangely enough. 最初,它在每行的末尾添加了一个斜杠,甚至以.php结尾,但是现在它可以正常工作了,这很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.