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:


They link to it like this:



  • 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 ??
  • 1
    This answer stackoverflow.com/questions/3229371/… covers your first and third questions. Not sure about the second one. Commented Jul 25, 2011 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
    Commented Jul 25, 2011 at 17:01
  • 3
    @Itai It's referring site, since URLs was not generated properly in first place.
    – LazyOne
    Commented Jul 25, 2011 at 19:25

1 Answer 1


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.

  • 1
    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. Commented Mar 1, 2013 at 6:55
  • 1
    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. Commented Mar 1, 2013 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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