Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm running IIS 7 web server and getting an error 404 when trying to download a file with a # symbol anywhere in the file name.

http://www.server.com/files/my#filename.doc <-- does not download leads to 404 error.

If I remove the # symbol it works fine.

Can anyone suggest why this is happening and if there's a workaround?

Thanks

share|improve this question
add comment

migrated from stackoverflow.com May 15 '11 at 13:10

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 2 down vote accepted

Are you saying that the # is present in the filename itself?

The # is a meaningful character in the URL scheme (see RFC 3986). It separates the url path from the fragment id.

It could be that you will need to escape the octothorpe.

share|improve this answer
    
yes the actual file name contains the # symbol. I've tried using %23, no difference. –  Khalid Rahaman May 14 '11 at 1:23
    
Escaping won't help, so the first 2 lines of your answer are correct ;-0 –  anthonyg May 19 '11 at 10:31
add comment

You need to escape it to %23.

So it should be:

http://www.server.com/files/my%23filename.doc

share|improve this answer
add comment

I agree with the previous responses of escaping the '#' symbol to '%23'. When dealing with file names on a website, it is also a good rule of thumb to avoid using special characters and spaces to avoid compatibility issues. Also, from an SEO perspective, consider the following example:

http://mydomain.com/ThisIsMyKeywordFileName.pdf

Some search engines will be able to parse a keyword out of this file name, but others will determine that 'thisismykeywordfilename' is all one word. If you change it to the following:

http://mydomain.com/This-Is-My-Keyword-File-Name.pdf

Search engines will then be able to break out the keywords in your file names. If you use spaces in the file name, you may end up with an encoded URL in your address bar that looks like this:

http://mydomain.com/This%20Is%20My%20Keyword%20File%20Name.pdf.

Which is not real nice to look at. When escaping the '#' symbol, you will end up with escaped file names that look similar to the example above. A good strategy if possible would be to simplify your file naming, otherwise, escaped special characters are what you need to do.

share|improve this answer
add comment

You could try encoding the file name as follows.

http://www.server.com/files/my%23filename.doc

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.