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
# 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.
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.
Some browsers add a trailing slash because of recent history, clear you history and try again. You could also try in a different browser.
A similar question has already been asked:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.