Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Trailing Slash for URLs

         

leko

12:51 am on Nov 4, 2014 (gmt 0)

10+ Year Member



I am new to WordPress and need to commit to a URL structure. What is the consensus on the trailing slash for URLs?

Which is better for SEO:

www.example.com/
or
www.example.com

lorax

1:40 am on Nov 4, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld leko!

Go with the trailing slash as that is the WordPress default. It will be harder to work with if you don't.

leko

1:50 am on Nov 4, 2014 (gmt 0)

10+ Year Member



Thanks for the welcome Lorax!

I see that you can customize permalinks in WordPress dashboard settings area, but some SEO tutorials suggest preventing duplicate content due to googlebot considering the following URLs as different

www.example.com
www.example.com/
www.example.com/index.php
example.com
example.com/
example.comindex.php

So then would I need to put this in .htaccess ?

# Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

not2easy

2:00 am on Nov 4, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



In WordPress, you would control a trailing slash in your permalink settings, not in .htaccess.

leko

2:39 am on Nov 4, 2014 (gmt 0)

10+ Year Member



How do you deal with canonicalization of URLs with versus without trailing slash?

For example, to deal with canonicalization of www versus non-www, it is suggested to use the below to redirect to www. Using this logic, would I then need to force trailing slash (in .htaccess in addition to wordpress permalink settings) ? If .htaccess is used to deal with canonicalization of www then would I use .htaccess to deal with canonicalization of trailing slash? Do you see my logic?

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

lucy24

4:00 am on Nov 4, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Didn't you just ask this in another thread? The trailing slash in
example.com
vs.
example.com/
is irrelevant. It's done in the browser; the server doesn't see any difference. (The two slashes :// between protocol and domain name are also supplied by the browser.) Slashes only matter after this first one. Er, first three.

The form
example.comindex.php
without slash simply does not and cannot occur. Go ahead: try typing it into your browser. You'll eventually get an error message from the browser saying it couldn't find the domain.

leko

6:42 am on Nov 4, 2014 (gmt 0)

10+ Year Member



Slashes only matter after this first one. Er, first three.


Ah I see, makes sense. Problem was that I read

www.example.com/blog/ was different from
www.example.com/blog

so I assumed
www.example.com/ was different from
www.example.com

but why is this person concerned about the "third" slash here:

[webmasters.stackexchange.com...]

lucy24

8:07 am on Nov 4, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I dunno. If someone really enjoys worrying, I guess you gotta find something to worry about ;) As long as you've got the with/without part of the domain name canonicalized, the rest will take care of itself. Maybe the person read something about trailing slashes and didn't realize that the front page is a special case.

phranque

8:11 am on Nov 4, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



so I assumed
www.example.com/ was different from
www.example.com
the answer is that the url path on the server starts with the 3rd slash, which indicates the root directory aka "home page" if you are using a default directory index document.
everything before the 3rd slash is the hostname, so whether it is the browser, the server, or a search engine fixing things up they are essentially the same url.