Forum Moderators: phranque

Message Too Old, No Replies

Trailing slashes, what do search engines prefer?

         

JAB Creations

9:07 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sure this has been asked before though couldn't find any threads; do search engines have a URL preference for trailing slash, the lack of a trailing slash, or do they treat such URL's indifferently?

I have no problem being able to have my sites do either along with redirects from either or, I'm simply curious what if any preference the search engines have.

- John

jdMorgan

9:19 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTTP convention:

A URL ending with a slash indicates a directory listing of files or a directory index page, i.e the "home page of a directory".
A URL not ending with a slash indicates a resource -- a page, for example.

Other than that, SEs don't care, so there's no reason to make your URL longer by adding a slash.

Jim

buckworks

9:21 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The search engines are okay either way .... what's important is to be consistent so that URL variations don't end up splitting your link popularity.

Including the trailing slash can save a step for the server when links are clicked.

jdMorgan

9:31 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Including the trailing slash can save a step for the server when links are clicked.

If and only if the URL resolves to a directory or directory index, in which case, it should have a slash to begin with.

example.com/foo refers to the page called "foo"
example.com/foo/ refers to the file listing for the subdirectory "/foo", or to the index page located in the subdirectory "/foo".

Jim

phranque

9:31 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



this is also being discussed in this current thread:
[webmasterworld.com...]

JAB Creations

9:32 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is what I was thinking and have been using trailing slashes for directories (with a rewrite) and not using them for "pages". Consistency is a critical aspect of design though I'm still glad you pointed that out. :)

One odd thing I noticed was that with the new version of my site if I don't have a directory in the file system it would not rewrite example.com/music to example.com/music/ while if the directory exists (even if empty) it will.

Is there a way I can modify my Apache script in .htaccess to not require empty directories for that?

- John

RewriteEngine on
RewriteRule !\.(css圭ur圯xe夙if夙z多tml多3m夷co夸pg夸s妃ov妃p3妃p4妃si如df如l如ng字ar存wf宇tf宇xt安mv寺html寺ml寺pi屹ip)$ index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^index\.php$ [%{SERVER_NAME}...] [NC,R=301,L]

JAB Creations

9:35 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@phranque, thanks to PHP's limit parameter I can explode only the first slash to set $piece[0] as the section and $piece[1] as the page URL even if it has several slashes. I vigorously test my work and preventing duplicate content is one of the many things I've worked hard towards. :)

- John

jdMorgan

9:52 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are seeing the action of Apache mod_dir (see documentation). If the directory does not exist, you certainly don't want to add a slash, because then the result will be a 301 redirect to that directory followed by a 404 on that directory.

Unrelated observation: Your first rule above is missing the [L] flag, and the second rule above is missing the trailing slash on the redirect URL following "%{SERVERNAME}". This will invoke an additional mod_dir redirect.

Also, if you want ro use [NC] on the second rule, you'll have to use it on the second rule's RewriteCond as well, otherwise having the [NC] flag on the rule won't accomplish anything.

Jim

JAB Creations

10:09 pm on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess I'll stick to manually creating "section" directories then, not a pain since I don't do that often any way. :)

I removed NC, all the file paths are case sensitive to begin with so not sure why I had it.

I've updated my script (is that what Apache's syntax is technically referred to as?) so here are the changes. Thanks for your help and everyone's input!

- John

RewriteEngine on
RewriteRule !\.(css圭ur圯xe夙if夙z多tml多3m夷co夸pg夸s妃ov妃p3妃p4妃si如df如l如ng字ar存wf宇tf宇xt安mv寺html寺ml寺pi屹ip)$ index.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^index\.php$ [%{SERVER_NAME}...] [R=301,L]