WordPress.org

Ready to get started?Download WordPress

Forums

Force trailing slash onto WordPress Page URLs (4 posts)

  1. pcmt
    Member
    Posted 8 years ago #

    Could someone please explain how to alter the .htaccess file to force a trailing slash on the end of permalink WordPress page URLs that use the page slug? (eg ww*.domain.com/page-slug/) Yahoo is indexing all default page URLs, that are linked to with a trailing slash, without the trailing slash (eg ww*.domain.com/page-slug).

    This means that someone who finds a WordPress page in Yahoo and decides to link to it could do so without the trailing slash. Then if Google follows that link it will likely index both versions - I am seeing this happening and it is not a good thing.

  2. higher-logic
    Member
    Posted 7 years ago #

    Ok, this is really late, but I might as well answer it. Add the following to your .htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://domain.com/$1/ [QSA,L,R=301]

  3. h8dk97
    Member
    Posted 7 years ago #

    I was looking for something like this as well. Thanks.

    What about redirecting from www to non-www domain?

  4. h8dk97
    Member
    Posted 7 years ago #

    How would you change this rule so that it doesn't apply to files with .html extension?

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://domain.com/$1/ [QSA,L,R=301]

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.