Different behaviours of treating \ (backslash) in the url by FireFox and Chrome - css

BACKGROUND
According to my experience when my ubuntu workstation is configured on domain with active directory, the user name created for me was according to the following pattern.
domain_name\user_name
Using the userdir extensions of apache on linux will require to use user name in the URL in order to access public_html in the home directory.
http://localhost/~domain_name\user_name
PROBLEM A:
Chrome converts all the backslash '\' characters in the URL to forward slash '/' and the resultant url becomes as under that is totally different and always results Not Found.
http://localhost/~domain_name/user_name
Firefox on the other hand does not convert back slash to forward slash so http request to intended target is served by web server.
Common solution is to encode back slash in %5C.
PROBLEM B:
If we use a similar path (containing \ in path) in CSS #import construct, the import process of css file as HTTP Get Request is failed by reporting 404 error and the URL reported in the 404 error miss the presence of \ altogether. It means \ is removed from the URL before to invoke GET request against it.
This behavior is common in Firefox and Chrome. But they have uncommon solutions
Firefox needs escaped back slash to work in css import process.
#import url("http://localhost/~domain_name\\user_name/path/to/css");
Chrome as usual needs an encoded back slash solution.
#import url("http://localhost/~domain_name%5Cuser_name/path/to/css");
What is the unified solutions to deal with \ in URL?
Is there a way to avoid a \ to appear in user name?

The unified solution to deal with backslash in a URL is to use %5C. RFC 2396 did not allow that character in URLs at all (so any behavior regarding that character was just error-recovery behavior). RFC 3986 does allow it, but is not widely implemented, not least because it's not exactly compatible with existing URL processors.
Chrome, in particular, does the same thing as IE: assumes you meant a forward slash any time you type a backslash, as you discovered, because that's what Windows file paths do.

Try using the Slashy add-on in the firefox to help you with it.Here's a link to it.
Slashy

This backslash auto conversion issue has fixed in Chrome version >= 53.0.2785.116.
Now the backslashes are treated properly as %5C.

Related

Should the server treat such endpoints as different? [duplicate]

When should a trailing slash be used in a URL? For example - should my URL look like /about-us/ or like /about-us?
I am fully aware of the SEO-related issues - duplicate content and the canonical thing; I'm trying to figure out which one I should use in the context of serving pages correctly alone.
For example, my colleague is thinking that a trailing slash at the end means it's a "folder" - a "directory", so this is not a correct style. But I think that without a slash in the end - it's not quite correct either, because it almost looks like a folder, but it isn't and it's not a normal file either, but a filename without extension.
Is there a proper way of knowing which to use?
It is not a question of preference. /base and /base/ have different semantics. In many cases, the difference is unimportant. But it is important when there are relative URLs.
child relative to /base/ is /base/child.
child relative to /base is (perhaps surprisingly) /child.
In my personal opinion trailing slashes are misused.
Basically the URL format came from the same UNIX format of files and folders, later on, on DOS systems, and finally, adapted for the web.
A typical URL for this book on a Unix-like operating system would be a file path such as file:///home/username/RomeoAndJuliet.pdf, identifying the electronic book saved in a file on a local hard disk.
Source: Wikipedia: Uniform Resource Identifier
Another good source to read: Wikipedia: URI Scheme
According to RFC 1738, which defined URLs in 1994, when resources contain references to other resources, they can use relative links to define the location of the second resource as if to say, "in the same place as this one except with the following relative path". It went on to say that such relative URLs are dependent on the original URL containing a hierarchical structure against which the relative link is based, and that the ftp, http,
and file URL schemes are examples of some that can be considered hierarchical, with the components of the hierarchy being separated by "/".
Source: Wikipedia Uniform Resource Locator (URL)
Also:
That is the question we hear often. Onward to the answers! Historically, it’s common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to
denote a file:
http://example.com/foo/ (with trailing slash, conventionally a directory)
http://example.com/foo (without trailing slash, conventionally a file)
Source: Google WebMaster Central Blog - To slash or not to slash
Finally:
A slash at the end of the URL makes the address look "pretty".
A URL without a slash at the end and without an extension looks somewhat "weird".
You will never name your CSS file (for example) http://www.sample.com/stylesheet/ would you?
BUT I'm being a proponent of web best practices regardless of the environment.
It can be wonky and unclear, just as you said about the URL with no ext.
I'm always surprised by the extensive use of trailing slashes on non-directory URLs (WordPress among others). This really shouldn't be an either-or debate because putting a slash after a resource is semantically wrong. The web was designed to deliver addressable resources, and those addresses - URLs - were designed to emulate a *nix-style file-system hierarchy. In that context:
Slashes always denote directories, never files.
Files may be named anything (with or without extensions), but cannot contain or end with slashes.
Using these guidelines, it's wrong to put a slash after a non-directory resource.
That's not really a question of aesthetics, but indeed a technical difference. The directory thinking of it is totally correct and pretty much explaining everything. Let's work it out:
You are back in the stone age now or only serve static pages
You have a fixed directory structure on your web server and only static files like images, html and so on — no server side scripts or whatsoever.
A browser requests /index.htm, it exists and is delivered to the client. Later you have lots of - let's say - DVD movies reviewed and a html page for each of them in the /dvd/ directory. Now someone requests /dvd/adams_apples.htm and it is delivered because it is there.
At some day, someone just requests /dvd/ - which is a directory and the server is trying to figure out what to deliver. Besides access restrictions and so on there are two possibilities: Show the user the directory content (I bet you already have seen this somewhere) or show a default file (in Apache it is: DirectoryIndex: sets the file that Apache will serve if a directory is requested.)
So far so good, this is the expected case. It already shows the difference in handling, so let's get into it:
At 5:34am you made a mistake uploading your files
(Which is by the way completely understandable.) So, you did something entirely wrong and instead of uploading /dvd/the_big_lebowski.htm you uploaded that file as dvd (with no extension) to /.
Someone bookmarked your /dvd/ directory listing (of course you didn't want to create and always update that nifty index.htm) and is visiting your web-site. Directory content is delivered - all fine.
Someone heard of your list and is typing /dvd. And now it is screwed. Instead of your DVD directory listing the server finds a file with that name and is delivering your Big Lebowski file.
So, you delete that file and tell the guy to reload the page. Your server looks for the /dvd file, but it is gone. Most servers will then notice that there is a directory with that name and tell the client that what it was looking for is indeed somewhere else. The response will most likely be be:
Status Code:301 Moved Permanently with Location: http://[...]/dvd/
So, totally ignoring what you think about directories or files, the server only can handle such stuff and - unless told differently - decides for you about the meaning of "slash or not".
Finally after receiving this response, the client loads /dvd/ and everything is fine.
Is it fine? No.
"Just fine" is not good enough for you
You have some dynamic page where everything is passed to /index.php and gets processed. Everything worked quite good until now, but that entire thing starts to feel slower and you investigate.
Soon, you'll notice that /dvd/list is doing exactly the same: Redirecting to /dvd/list/ which is then internally translated into index.php?controller=dvd&action=list. One additional request - but even worse! customer/login redirects to customer/login/ which in turn redirects to the HTTPS URL of customer/login/. You end up having tons of unnecessary HTTP redirects (= additional requests) that make the user experience slower.
Most likely you have a default directory index here, too: index.php?controller=dvd with no action simply internally loads index.php?controller=dvd&action=list.
Summary:
If it ends with / it can never be a file. No server guessing.
Slash or no slash are entirely different meanings. There is a technical/resource difference between "slash or no slash", and you should be aware of it and use it accordingly. Just because the server most likely loads /dvd/index.htm - or loads the correct script stuff - when you say /dvd: It does it, but not because you made the right request. Which would have been /dvd/.
Omitting the slash even if you indeed mean the slashed version gives you an additional HTTP request penalty. Which is always bad (think of mobile latency) and has more weight than a "pretty URL" - especially since crawlers are not as dumb as SEOs believe or want you to believe ;)
When you make your URL /about-us/ (with the trailing slash), it's easy to start with a single file index.html and then later expand it and add more files (e.g. our-CEO-john-doe.jpg) or even build a hierarchy under it (e.g. /about-us/company/, /about-us/products/, etc.) as needed, without changing the published URL. This gives you a great flexibility.
Other answers here seem to favor omitting the trailing slash. There is one case in which a trailing slash will help with search engine optimization (SEO). That is the case that your document has what appears to be a file extension that is not .html. This becomes an issue with sites that are rating websites. They might choose between these two urls:
http://mysite.example.com/rated.example.com
http://mysite.example.com/rated.example.com/
In such a case, I would choose the one with the trailing slash. That is because the .com extension is an extension for Windows executable command files. Search engines and virus checkers often dislike URLs that appear that they may contain malware distributed through such mechanisms. The trailing slash seems to mitigate any concerns, allowing the page to rank in search engines and get by virus checkers.
If your URLs have no . in the file portion, then I would recommend omitting the trailing slash for simplicity.
Who says a file name needs an extension?? take a look on a *nix machine sometime...
I agree with your friend, no trailing slash.
From an SEO perspective, choosing whether or not to include a trailing slash at the end of a URL is irrelevant. These days, it is common to see examples of both on the web. A site will not be penalized either way, nor will this choice affect your website's search engine ranking or other SEO considerations.
Just choose a URL naming convention you prefer, and include a canonical meta tag in the <head> section of each webpage.
Search engines may consider a single webpage as two separate duplicate URLS when they encounter it with and without the trailing slash, ie example.com/about-us/ and example.com/about-us.
It is best practice to include a canonical meta tag on each page because you cannot control how other sites link to your URLs.
The canonical tag looks like this: <link rel="canonical" href="https://example.com/about-us" />. Using a canonical meta tag ensures that search engines only count each of your URLs once, regardless of whether other websites include a trailing slash when they link to your site.
The trailing slash does not matter for your root domain or subdomain. Google sees the two as equivalent.
But trailing slashes do matter for everything else because Google sees the two versions (one with a trailing slash and one without) as being different URLs.
Conventionally, a trailing slash (/) at the end of a URL meant that the URL was a folder or directory.
A URL without a trailing slash at the end used to mean that the URL was a file.
Read more
Google recommendation

Nginx url rewrite uppercase to lowercase

is there a way to only translate the requested url to lowercase and not things like image sources or links etc?
I tried this approach but it also translates the image sources to lowercase so they wont work anymore.
How i can translate uppercase to lowercase letters in a rewrite rule in nginx web server?
Thanks!

# in URL required but doesn't work on PC in Qt app

I have a Qt app that I have inherited and have to support. There is a piece of code that generates a URL that looks like this:
http://foo.bar.com:8000/#/workitem/71327434512586907410/report
The page is then loaded with setUrl
On a Mac this works fine, but on Windows the page is not loaded, and I do not even see the request reach the server. I found this:
https://bugreports.qt.io/browse/QTWEBKIT-56
On the Mac where it works I do not see the # in the request that the server gets. But if I remove the # in the code, I get a 404.
So my questions are this:
What does the # mean in this context?
Why is it required for this URL to be recognized?
Why does it work on Mac and not on Windows? Is it that bug in the link?
The webserver is nginx, and the framework is falcon.
I have a bit more info on this.
When the URL contains the # I see in the nginx log this:
POST /workitem/67876029556368716590/report
And the request is successfully served.
But when the URL does not have the # I see this in the log:
GET /workitem/67876029556368716590
And that returns the 404.
Another update:
I have figured out that the # is a Angular JS routing thing:
AngularJS routing without the hash '#'
So now my only question is, is there a Qt bug that is preventing this from working in Windows.
'#' is an unsafe character and should be encoded.
All unsafe characters must always be encoded within a URL. For
example, the character "#" must be encoded within URLs even in
systems that do not normally deal with fragment or anchor
identifiers, so that if the URL is copied into another system that
does use them, it will not be necessary to change the URL encoding.
http://www.ietf.org/rfc/rfc1738.txt
This turned out to be a big red herring. I was able to modify the system so that I did not need the # in the URL and it still didn't work. Turned out the issue was that the code was trying to download jquery using SSL and it did not work on systems that did not have the SSL libs installed. I changed the code to download jquery from my server instead of the internet and it all worked.

Path to ISAPI filters with double back slash.

Recently i had an EPIserver site throing an error becaus it could not load the LoadLibraryEx for ISAPI-filter "C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll". I checked the IIS and the path looked very weird with 2 backslashes. Like this: "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\aspnet_filter.dll" so i changes the path by removing one backslash and checking that the path was correct. Ths site worked.
Now i tried to install a new EPiSite and the error came up that it could not load the ISAPI filters but the path was with double backslash!
3.I read on the internet and found a forum thread about the double backs slash that said that it should be changed in the C:\Windows\System32\inetsrv\config\applicationHost.config. I checked and the path there was also with doubble slash so i changed it.
But now the site gives the same error but with only one back slash. It cant load it.
I dont understand ISAPI filters very well or the IIS, so i wonder if the backslash is something that should be there or if its a mistake, and ofcourse any help to reconfigure it to work is appreciated.
I recommend you to check your machine.config also for the filter path.
There might be some problem there.

IIS7 URL Redirect Not working for ASPX pages with colons in the name

This is related to a previous (unanswered) issue I've had with trying to catch request errors in the Global.asax, but it now appears to be more widespread.
The URL redirect feature in IIS7 will not handle URLs which both end in .aspx and contain a colon anywhere in the url. Rather than follow its own redirect rules, IIS7 treats .aspx pages differently to others, and throws
[NotSupportedException: The given
path's format is not supported.]
Has anyone else encountered this issue?
Possibly IIS is treating the colon as if it should precede a port number (http://mysite.com:12345) or some other invocation to an IIS- or OS-level command. So, it may be suspicious of some kind of code injection.
You might try this thread: Why is using a URL containing a colon considered as a "potentially dangerous request"? .
Hanselman also had an interesting bit up about url rewriting black magic - check the middle of the article for more on the colon character. http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

Resources