Trailing slashes: yes or no?

I am working on a new project using Apache mod_rewrite and PHP to get nice urls.

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

Note that there is no trailing slash (this is how I write it in href <a>s attributes ).

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

Is this a bad practice? I am wondering if it would be better to allow only one path or, by default, to use the best slashes in all of my links.

Thank.

+3
source share
3 answers

The trailing slash usually indicates the directory, without the trailing slash the file.

, , . 301 , .

+1

- , /etc .

.

+6

I would say that for consistency, allow only what you use and then redirect ( 301 ) the wrong (with trailing) to the right (without trailing), so you won’t duplicate the content .

Of course, right and wrong it all depends on you.

0
source

Source: https://habr.com/ru/post/1750452/


All Articles