skip to Main Content

I can’t remove the trailing slash from homepage link example.com/blog/.
I tried it from .htaccess as well as from site config.

RewriteRule (.+)/$ $1 [R=301,L]

It is working from permalinks, and all categories and posts being without trailing slash.
But homepage still has it and is really annoying and not good for my SEO.

** blog is a subdirectory

also treid to define htaccess like the following:

Options -Indexes
DirectorySlash Off

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

How can I solve it?

2

Answers


  1. Try setting the following in .htaccess:

    DirectorySlash Off
    

    Since /blog is (I assume) a physical directory then mod_dir will ordinarily append the trailing slash in order to “fix” the URL.

    However, whether this will now work without the trailing slash is another matter, since you will now need to internally rewrite the request to include the trailing slash.

    UPDATE: To remove the “file list” when accessing /blog you should add the following directive to the top of your .htaccess file (this is a good idea anyway, regardless of the current problem):

    Options -Indexes
    

    To make this “work” without the trailing slash, you will need to manually internally rewrite the request to include the trailing slash (since that is strictly the “correct” URL since this is a physical directory), or take it one step further (and avoid mod_dir requesting the DirectoryIndex) and rewrite to /blog/index.php – which I assume is the required filename, being WordPress.

    In the .htaccess file in the document root, add the following before any existing mod_rewrite directives:

    RewriteRule ^blog$ /blog/index.php [L]
    
    Login or Signup to reply.
  2. Try to go to Settings -> General -> WordPress Address (URL) and remove the trailing slash.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search