Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best practice for URL path casing and spacing?

I want to know what is considered a good practise for casing and spacing in URL paths.

Casing:

  • Lower-case
  • Camel case
  • Pascal case

Spacing:

  • None
  • Hyphen
  • Underscore
../data/upload_data  
../data/upload-data  
../data/uploadData  
../Data/UploadData  

What do you think? Which is better?

like image 905
Pk King X11 Avatar asked Jul 13 '16 08:07

Pk King X11


People also ask

Should URL be CamelCase or dash?

We recommend that you use hyphens (-) instead of underscores (_) in your URLs. Coming from a programming background, camelCase is a popular choice for naming joint words. But RFC 3986 defines URLs as case-sensitive for different parts of the URL.

What is URL path?

A URL (Uniform Resource Locator) identifies a resource on a remote server and gives the network location on that server. The URL path is the string of information that comes after the top level domain name. You can use the HTTP-proxy to block websites that contain specified text in the URL path.

Can I use CamelCase in URL?

You CAN use CamelCase, periods, or hyphens in your URL. You didn't ask about underscores, but you can use those too.

Can we use hyphen in REST URL?

REST API resource names Resource names exposed in a REST API should use all lowercase characters. Resource names may include hyphens. Resource names should not include underscores or other punctuation (sole exception is the hyphen).


1 Answers

Three common URL designs:

  • The most common design is: everything in lowercase and - as separator. This is the default in many CMS (including the most popular CMS, WordPress), and for example also used by Stack Overflow: the last path segment of your question’s URL is

    /whats-the-best-practice-for-url-path-casing-and-spacing
    
  • Wikipedia (and, by default, all MediaWiki sites) use correct case and _ as separator. For example, the page about Stack Overflow has this last path segment:

    /Stack_Overflow
    

    (which is different from /Stack_overflow)

  • Many (early) wikis use CamelCase and no separator. For example, the page about Stack Overflow in the first wiki (using WikiWikiWeb) has this last segment in the query component:

    StackOverflow
    

Pro separator: It’s easier to see what the string means; and you can avoid misunderstandings (think of teacherstalking: teachers talking, teacher stalking). While CamelCase could help here, it doesn’t work so well for longer strings, e.g., whats-the-best-practice-for-url-path-casing-and-spacing is easier to grasp than WhatsTheBestPracticeForUrlPathCasingAndSpacing.

Pro correct case: If your site has pages about different things written the same except for different case (e.g., "Stack Overflow" for the site/company, "Stack overflow" for the programming concept; or "Love" for the noun, "love" for the verb), this is a simple way to disambiguate.

Pro CamelCase: Words written that way can automatically be linked to their corresponding pages; authors don’t have to use hyperlink markup.

Unless your site is a wiki with many authors that don’t know markup so well (in which case CamelCase might be helpful), or something like an encyclopedia that defines things that are typically described by one or only a few words (in which case correct case might be helpful), I would go with the most popular way: use lowercase and the hyphen (-) as separator. This is what people are used to see.

Google recommends this, too:

Consider using punctuation in your URLs. The URL http://www.example.com/green-dress.html is much more useful to us than http://www.example.com/greendress.html.

We recommend that you use hyphens (-) instead of underscores (_) in your URLs.

like image 76
unor Avatar answered Oct 10 '22 03:10

unor