简体   繁体   English

如何在Wordpress的URL末尾添加“ /”

[英]How to add “/” on URL end in Wordpress

I have a problem with my Wordpress site. 我的Wordpress网站有问题。 I have duplicate content on my site because my Wordpress showing up pages with "/" and without "/". 我的网站上有重复的内容,因为我的Wordpress显示的页面带有“ /”而没有“ /”。 How can i change it to this: when on page we don't have "/" on URL end then please redirect to version with "/". 我如何将其更改为:在页面上,如果URL末尾没有“ /”,请重定向到带有“ /”的版本。 Eg: if adress is www.web.com/page please redirect to www.web.com/page/ Thanks for help :)! 例如:如果地址是www.web.com/page,请重定向到www.web.com/page/感谢您的帮助:)!

I think you need to edit your htaccess : 我认为您需要编辑htaccess:

Right below the RewriteEngine On line, add: 在RewriteEngine On行下面,添加:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301] 

Hope this will solve your problem. 希望这能解决您的问题。

Go to Settings >> Permalinks >> Custom Structure and in custom structure add "/" at the end. 转到设置>>永久链接>>自定义结构,然后在自定义结构的末尾添加“ /”。 This will work 这会起作用

Right below the RewriteEngine On line in .htaccess, add 在.htaccess中的RewriteEngine On行下面,添加

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R] 

Try to add this to .htaccess in the root of your site. 尝试将其添加到网站根目录中的.htaccess中。

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

I added to index.php file this code. 我将此代码添加到index.php文件。 It's ok ;) 没关系 ;)

 if (substr($_SERVER['REQUEST_URI'], -1) != "/") { header('HTTP/1.1 301 Moved Permanently'); header('Location: '.$_SERVER['REQUEST_URI'].'/'); die; } 

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

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