I have the following RewriteRule:

RewriteRule ^like/(.+)$ ask.php/$1

Which works just fine for requests like:


But for requests where one of the path parts contains an escaped slash (%2F), the server spits out a 404 Not Found error:


Is there any way to fix this? I tried both [B] and [NE] flags (separate and together) but nothing worked.

Edit: I also tried:

RewriteRule ^like/ ask.php
# or
RewriteRule ^like/(.*) ask.php

So that it doesn't necessarily have to match the slash. It's still not working.

  • Is there a directory path, using your example, called "/like/one/two+things/" where "two+things" is a subdirectory of "one" which is a subdriectory of "like"? If not, you can't have filenames (at least in Unix) with a slash in them and I'd be willing to bet that if Apache allows an escaped slash there's a potential security issue. – Dennis Williamson May 17 '10 at 13:19
  • No, there's no such path. But I don't see why it matters, since it should be internally rewritten to ask.php/$1, so there's no security issue :/ – Felix May 17 '10 at 13:33

Apache directive helped me

AllowEncodedSlashes On  

I found the answer here here. To quote the relevant bits:

The naked "%2f" is allowed in a query string. but not in a URL. In order to be valid, it would have to be encoded as %252f, which I think you will find to work as you expect.

Because the URL is itself invalid, the server is rejecting it before any apache modules are invoked.

For more information, see RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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