Remove trailing slash in wordpress blog URL

I decided to use wordpress to power my blog section. I created a folder under my root directory of my site titled blog. Now when I visit http://trekeffect.dev/blog I get redirected to http://trekeffect.dev/blog/ with the trailing slash. How can I remove the trailing slash?

.htaccess inside blog folder is

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

# END WordPress

.htaccess i am using in my project rrot folder is

RewriteRule ^blog/$ /blog [R=301]

Any help will be really appreciable. Thanks in advance.

Related posts

Leave a Reply

3 comments

  1. Mod_dir will automatically redirect any request for a directory that doesn’t end with a trailing slash. This is because there’s a security loophole that allows anyone to see the contents of a directory by leaving the trailing slash off. You can, of course, turn off this feature, but then you’d need to ensure you prevent this from happening by yourself. So something like this in your vhost config:

    DirectorySlash Off
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*[^/])$ /$1/ [L]
    

    Not sure if this will work in an htaccess file because when someone goes to “/blog“, they’re already bypassing any rules in your document root and the slash/noslash issue can’t be dealt with by then.

  2. This question has been answered here: Remove trailing slashes

    However, it must be said that keeping the trailing slash would be your best bet for SEO/UX, as including the trailing slash improves page load time, which is a factor in SE rankings and in positive user experience.

    How including the trailing slash improves page load time:

    How page load time improves rankings (and conversion rates):