开发者

URLs: Files and Directories with the same name?

开发者 https://www.devze.com 2023-03-28 03:38 出处:网络
In an URL scheme, is it in any way disadvantageous if a directory and a file have the same name? I provide an example to illustrate what I mean:

In an URL scheme, is it in any way disadvantageous if a directory and a file have the same name?

I provide an example to illustrate what I mean:

Let's say you want to do pagination. You could do it like this:

http://example.com/watches/page1
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

You could interpret that as: There is a directory 'watches' which has 4 files – 'page1' to 'page4'.

Now, the first page is probably going to be accessed quite often, so it makes sense to shorten the link to it:

http://example.com/w开发者_JS百科atches
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

The first link will still show page 1, but the 'page1' is left off. And it will NOT redirect to

http://example.com/watches/page1

as that would force another round trip to the server.

You could interpret that as: There is a file named 'watches' (which shows the first page in the category watches), and there is a directory 'watches' which has 3 files – 'page2' to 'page4'.

Here is my question again: Is it in any way disadvantageous if a directory and a file have the same name, like 'watches' in the above example?

Here are my thoughts on it:

In terms of SEO, it probably is not disadvantageous, as AFAIK search engines have no notion of directories and thus treat URLs as blobs of characters. And as long as the URLs are different – which they are in my example – the search engine does not bother.

In case someone wants to archive my website with a web crawler like wget and mirror its contents on a local HDD, it could be a problem, as most file systems don't allow more than one file/directory to have the same name. However, IMHO this could easily be solved, e.g. by using wget's -E option, which adds the .html extension to HTML files, but not to directories.

Other than that, I see no problems. Do you?


By and large nowadays web servers do not read URI's as a directories and files, but as an address for a resource, and in many if not the majority of cases, the routing between the URI and the resource is complex. This question as an example is not an HTML file in a directory. Also web crawlers don't as a consequence have to cope with structures that don't work as filenames either.

I'm not sure quite what your issue is, but I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号