简体   繁体   English

.htaccess 301重定向尾部斜杠

[英].htaccess 301 redirect Trailing Slash

In my website, I'd like to redirect all pages with a trailing slash to the URL without trailing slash. 在我的网站中,我想将所有带有斜杠的页面重定向到URL,而不带斜杠。 I'm trying to find the right code that will actually work, and I have tried numerous versions of htacess codes that are supposed to to achieve redirect. 我试图找到可以正常工作的正确代码,并且尝试了许多版本的htacess代码,这些版本应该能够实现重定向。 I have read many articles about this issue and tested many possible solutions. 我已经阅读了许多有关此问题的文章,并测试了许多可能的解决方案。 Still haven't found an actual solution though. 仍然没有找到实际的解决方案。

Here's an example 这是一个例子

RewriteEngine on
RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,NE,R=301]

No redirect it happening here. 没有重定向发生在这里。

Is there something else that would affect redirection? 还有其他会影响重定向的东西吗? Something I might be missing? 我可能会缺少什么? Do you have any suggestions? 你有什么建议吗?

----------------------------------------------------------- -------------------------------------------------- ---------

SOLUTION

The solution to this was to place the code AT THE TOP OF THE HTACCESS FILE . 解决方案是将代码放在HTACCESS文件的顶部 I was always placing it at the end of the file 我一直把它放在文件的末尾

Try this one: 试试这个:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^(.+)/$  /$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM