简体   繁体   中英

How to add “/” on URL end in Wordpress

I have a problem with my Wordpress site. I have duplicate content on my site because my Wordpress showing up pages with "/" and without "/". How can i change it to this: when on page we don't have "/" on URL end then please redirect to version with "/". Eg: if adress is www.web.com/page please redirect to www.web.com/page/ Thanks for help :)!

I think you need to edit your htaccess :

Right below the RewriteEngine On line, add:

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

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

Try to add this to .htaccess in the root of your site.

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

I added to index.php file this code. It's ok ;)

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

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.

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