Remove trailing slash from ALL URLs on a site

I'm a little new to the whole .htaccess, and I tried to change it so that none of my links had trailing slashes at the end of their respective URLs. My site is filmblurb.org.

The code for .htaccess, where Wordpress starts and ends, is as follows:

# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 

I would appreciate it if someone could lead me in the right direction on how to fix this. Thanks.

+4
source share
3 answers

You can add a RewriteRule to eliminate the trailing slash:

 RewriteRule ^(.*)/$ $1 [R=301,L] 
+8
source

The problem is not caused by .htaccess, but rather by a combination of wordpress permalinks and .htaccess.

  • Log in to your site and go to permalinks, and then if you don’t use the custom structure parameter, switch to it and don’t end with a slash at the end:

     /%category%/%postname% 
  • Then add this to your .htaccess file, above

     RedirectMatch 301 ^(.*)/$ /$1 

This is better than using rewrite, as it is a redirect, not a rewrite.

If this still does not work, I recommend you install the yoast seo plugin, and there is a setting for this.

+1
source

This works for me; removing all trailing slashes from all routes, emphasizing that REQUEST_URI starts with a slash (at least in .htaccess files):

 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /(.*)/$ RewriteRule ^ /%1 [R=301,L] 

Just don't use %{REQUEST_URI} (.*)/$ . Because the root directory of REQUEST_URI is /, leading a slash, and that would be misinterpreted as a trailing slash.

SOURCE: fooobar.com/questions/110630 / ...

0
source

All Articles