1

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

zekia
  • 4,527
  • 6
  • 38
  • 47

1 Answers1

1

Try this one:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^(.+)/$  /$1 [R=301,L]
Adam Chysky
  • 386
  • 1
  • 9
  • Hmm, then I believe the problem is on the server. I've been using this one for a long time. Do other mod_rewrite rules work? – Adam Chysky Apr 22 '15 at 11:09
  • Yes, I have tried other kinds of redirections in my htaccess file, and they all work properly (for example redirecting "example.com/index.php" to "example.com"). It's just the trailing slush thing that's refusing to work. – zekia Apr 22 '15 at 11:13
  • You can try to raise LogLevel and check the log to see what happens when apache goes through your rules. Go to httpd.conf file in apache directory and search for directive `LogLevel`. See this [answer](http://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite) for more details. – Adam Chysky Apr 22 '15 at 11:49
  • The stupid 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 – zekia Apr 30 '15 at 07:15