在目录中添加斜杠,在文件中删除斜杠 - .htaccess
我怎样才能让它发挥作用?我希望在目录处有一个尾部斜杠,但在文件处没有斜杠。所以 test.php/
变成 test.php
并且 test/folder
变成 test/folder/
?现在我写了这段代码,但是不起作用:
# Remove trailing slash from files
RewriteCond %{REQUEST_URI} ^/([^/]*)([.]{1})([^./]{1,})/$
RewriteRule . %1.%3 [R=301,L]
# Add trailing slash at directories
RewriteCond %{REQUEST_URI} ^/([^/.]*)$
RewriteRule . %1/ [R=301,L]
How can I get this to work? I want one single trailing slash at directories, but no slashes at files. So test.php/
becomes test.php
and test/folder
becomes test/folder/
? Now I wrote this code, but that doesn't work:
# Remove trailing slash from files
RewriteCond %{REQUEST_URI} ^/([^/]*)([.]{1})([^./]{1,})/$
RewriteRule . %1.%3 [R=301,L]
# Add trailing slash at directories
RewriteCond %{REQUEST_URI} ^/([^/.]*)$
RewriteRule . %1/ [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论