Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trailing slashes: yes or no? [duplicate]

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.

like image 882
user367217 Avatar asked Dec 27 '25 16:12

user367217


1 Answers

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.

like image 188
Pekka Avatar answered Dec 31 '25 18:12

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!