简体   繁体   English

删除Wordpress博客URL中的结尾斜杠

[英]Remove trailing slash in wordpress blog URL

I decided to use wordpress to power my blog section. 我决定使用wordpress驱动我的博客部分。 I created a folder under my root directory of my site titled blog. 我在网站的根目录下创建了一个名为blog的文件夹。 Now when I visit http://trekeffect.dev/blog I get redirected to http://trekeffect.dev/blog/ with the trailing slash. 现在,当我访问http://trekeffect.dev/blog时,我会以斜杠重定向到http://trekeffect.dev/blog/ How can I remove the trailing slash? 如何删除斜杠?

.htaccess inside blog folder is 博客文件夹中的.htaccess是

# 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 我在我的项目rrot文件夹中使用的.htaccess是

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. Mod_dir将自动重定向对不以斜杠结尾的目录的任何请求。 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. 不知道这是否可以在htaccess文件中使用,因为当有人进入“ /blog ”时,他们已经绕过了文档根目录中的所有规则,并且到那时斜杠/ noslash问题还无法解决。

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: 已经提出了类似的问题:

Remove trailing slashes 删除尾部斜杠

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. 但是,必须说,保持斜杠是SEO / UX的最佳选择,因为包括斜杠会缩短页面加载时间,这是SE排名和良好用户体验的一个因素。

How including the trailing slash improves page load time: 包括斜杠如何改善页面加载时间:

How page load time improves rankings (and conversion rates): 页面加载时间如何提高排名(和转化率):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM