2

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 2

0

Try to go to Settings -> General -> WordPress Address (URL) and remove the trailing slash.

Sign up to request clarification or add additional context in comments.

Comments

0

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]

5 Comments

yes this is a physical directory, - your solution is not working for me it is show me the file list : Index of /blog and the site working only with trailing slash any other idea? thx very much
Presumably WordPress is installed in the /blog subdirectory? I've updated my answer.
I tried that - not working -please see my post i edited it with the htaccess file
I am getting "Forbidden: You don't have permission to access /blog on this server." And permissions are ok
@MladenJanjetovic You'll get a 403 Forbidden if you have disabled directory indexes and there is no directory index document present in that directory (this is not a file permissions issue). However, as noted above, if you are actively removing the trailing slash on physical directories then you need to internally rewrite the request to "fix" the URL (by appending a trailing slash), otherwise, server behaviour is undefined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.