简体   繁体   中英

.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. 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. 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 . 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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