Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url with multiple forward slashes, does it break anything?

http://example.com/something/somewhere//somehow/script.js 

Does the double slash break anything on the server side? I have a script that parses URLs and i was wondering if it would break anything (or change the path) if i replaced multiple slashes with a single slash. Especially on the server side, some frameworks like CodeIgniter and Joomla use segmented url schemes and routing. I would just want to know if it breaks anything.

like image 545
Joseph Avatar asked Apr 15 '12 10:04

Joseph


People also ask

What does 2 forward slashes mean in a URL?

A double slash in the URL path is valid and will respond in the browser, but is typically unwelcome, as this could cause duplicate content issues if the CMS delivers the same content on two URLs (i.e. single slash and double slash).

Is forward slash allowed in URL?

Experiments of Mixing Slashes And found that all those browsers accept URLs written with forward slashes ( / , the correct form), URLs written with backslashes ( \ , an incorrect form) and URLs written with mixed slashes in their path part ( / & \ , another incorrect form).

What do multiple slashes mean?

It is very informal, looks like a variant of an emote which uses a singular slash, the double is probably influenced by programming comments, but hard to say. Particularly as a double slash in written work usually means "new line here". Follow this answer to receive notifications.

How do you fix a double slash in URL?

If the double slash in the page's permalink is generated by your CMS, you might need to address your developer for help. If the URL with a double slash is indexed in Google or has incoming external links, you can set the proper 301 redirects to the corrected URL.


2 Answers

HTTP RFC 2396 defines path separator to be single slash.

However, unless you're using some kind of URL rewriting (in which case the rewriting rules may be affected by the number of slashes), the uri maps to a path on disk, but in (most?) modern operating systems (Linux/Unix, Windows), multiple path separators in a row do not have any special meaning, so /path/to/foo and /path//to////foo would eventually map to the same file.

An additional thing that might be affected is caching. Since both your browser and the server cache individual pages (according to their caching settings), requesting same file multiple times via slightly different URIs might affect the caching (depending on server and client implementation).

like image 188
poncha Avatar answered Sep 28 '22 03:09

poncha


The correct answer to this question is it depends upon the implementation of the server!

Preface: Double-slash is syntactically valid according to RFC 2396, which defines URL path syntax. As amn explains, it therefore implies an empty URI segment. Note however that RFC 2396 only defines the syntax, not semantics of paths, including empty path segments, so it is up to your server to decide the semantics of the empty path.

You didn't mention the server software stack you're using, perhaps you're even rolling your own? So please use your imagination as to what the semantics could be!

Practically, I would like to point out some everyday semantic-related reasons which mean you should avoid double slashes even though they are syntactically valid:

  1. Since empty being valid is somehow not expected by everyone, it can cause bugs. And even though your server technology of today might be compatible with it, either your server technology of tomorrow or the next version of your server technology of today might decide not to support it any more. Example: ASP.NET MVC Web API library throws an error when you try to specify a route template with a double slash.

  2. Some servers might interpret // as indicating the root path. This can either be on-purpose, or a bug - and then likely it is a security bug, i.e. a directory traversal vulnerability.

  3. Because it is sometimes a bug, and a security bug, some clever server stacks and firewalls will see the substring '//', deduce you are possibly making an attempt at exploiting such a bug, and therefore they will return 403 Forbidden or 400 Bad Request etc, and refuse to actually do any further processing of the URI.

like image 36
Tim Lovell-Smith Avatar answered Sep 28 '22 05:09

Tim Lovell-Smith