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

Just recently noticed that some sites link with the URL incorrectly percent-encoded, to which my server (LAMP) responds with a 404 Not Found.

For example, for a URL of mine like this:

http://www.site.com/page.php?param=value

They link to it like this:

http://www.site.com/page.php%3Fparam%3Dvalue

So:

  • Who is wrong? My server for not understanding? or the linking site for not specifying the URL properly?
  • Could something be done to configure Apache to understand the misencoded query string delimiter (%3F instead of ?)?
  • If not, would it be safe to setup redirects by translating the %3F to ??
share|improve this question
1  
This answer stackoverflow.com/questions/3229371/… covers your first and third questions. Not sure about the second one. –  paulmorriss Jul 25 '11 at 16:27
    
Thanks! It covers mostly the third - I'd have to adapt it something more generic but OK. Still, I'd like to know if the referring site is in error or me? –  Itai Jul 25 '11 at 17:01
3  
@Itai It's referring site, since URLs was not generated properly in first place. –  LazyOne Jul 25 '11 at 19:25
add comment

1 Answer

up vote 2 down vote accepted

First things first, as @LazyOne said, the third-party URLs are not being properly generated, so the expectation is server to fail - as it is failing right now as you described.

Note that valid HTML and valid URLs are a different thing. You should escape entities for HTML content, but this is not true when writing links, image addresses, and calls for external files.

Before deciding to escape or not, ask yourself: is this going to be read by a user or by a browser? The answer will tell you which type of encoding you should use.

share|improve this answer
    
That last paragraph is incorrect. Which encoding you use is based on whether you're encoding for an XML/HTML document or a URI/URL. In some cases, you're doing one within the other. For example, ampersands have a special meaning in HTML and XML documents: they're used for character references (e.g. numeric character references such as & and & or character entity references such as &). But, aside from the document body, ampersands may also show up in meta data and link URLs. In the latter case, you would need to use both encodings, e.g. /foo?bar=1&baz=hello%20world. –  Lèse majesté Mar 1 '13 at 6:55
    
The problem with the URL in the question is that the URL encoding is done incorrectly. The reason ? and & in URLs need to be percent encoded is because they have special meanings when defining a query string. So other uses of these characters need to be percent encoded. But in this case, the question mark is supposed to indicate the start of the query string, so it should not have been percent encoded. –  Lèse majesté Mar 1 '13 at 7:12
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.