views:

131

answers:

3

Hello.

I'm working on a new project, using Apache's mod_rewrite and PHP to get pretty URLs.

Here's what my URLs look like:
http://example.tld/foo/bar/1/etc

Notice that there's no trailing slash (that's the way I write it in the href attributes of <a>s).

However, I'm also allowing http://example.tld/foo/bar/1/etc/ (trailing slash).

Is this bad practice? I'm wondering if it would be better to only allow one way or if I'd better use trailing slashes in all my links, by default.

Thanks.

+4  A: 

Trailing slashes can be a problem when using relative links in the document, as the browser will then treat /etc as a directory.

I would define one way, and set up an external redirect for the other.

Pekka
Relative links in pretty urls? Now there is an invitation to a headache.
Kristoffer S Hansen
@Kristoffer true :) But I've seen it done...
Pekka
A: 

I'd say for consistency only allow what you use yourself, then have it redirect (301) the wrong (with trailing) to the right one (without trailing), this way you won't have duplicate content either.

Of course whats right and wrong is entirely up to you.

Kristoffer S Hansen
+1  A: 

A trailing slash usually indicates a directory, without a trailing slash it indicates a file.

Allowing both with and without trailing slash will have a negative effect on your search engine ranking, because the same content is indexed twice. Stick to one, and do a 301 redirect if a user requests the other.

Sjoerd
That's what I was afraid of. I just realized that Stack Overflow, for example, allows both trailing slashes and no trailing slashes. I think I'm going for no trailing slashes then. There are no browsers that try to force a trailing slash, right?