10

I have a set of rewrite rules (in a .htaccess) something like this:

RewriteRule ^list/vendor/(.*)$ list.php?vendor=$1
RewriteRule ^list/product/(.*)$ list.php?product=$1
RewriteRule ^list/(.*)$ list.php?search=$1

(I don't think the first two are relevant to my question, though).

When I type in myserver.com/list/foo%2Cbar or even myserver.com/list/foo/bar, I get the results I expect: list.php is called with foo,bar and foo/bar in $_GET['search'].

But if I type in myserver.com/list/foo%2Fbar, it seems that the rule doesn't match! I get a 404 error instead. What can be going on here? Apache 2.2.14, if it matters.

(I tried in Firefox and Chrome, same results -- but it could be the browser acting up, of course).

LHMathies
  • 2,384
  • 16
  • 21

1 Answers1

18

Bah, I found it... Apache option AllowEncodedSlashes, which cannot be set per directory or from .htaccess, and which is Off by default.

Build-a-workaround time, if I can't get the hosting guys to turn it on in my virtual server.

cweiske
  • 30,033
  • 14
  • 133
  • 194
LHMathies
  • 2,384
  • 16
  • 21
  • When you do no want or it's impossible to change the server configuration you could replace all `/` characters by `-` before creating the URL. This won't be encoded as a `%xx` character. When you need the original string just replace the `-` with `/` again. – LEDfan Jun 17 '15 at 05:03
  • 1
    I've just run into the exact same problem trying to pass a URL as a parameter in a mod_rewrite URL. My solution was to double urlencode the URL I'm trying to pass, then at the receiving end I decode it. I'm using JavaScript and PHP so on the JavaScript end I use `encodeURIComponent(encodeURIComponent(urlToBePassed))` so that what actually gets passed as the parameter is `http://example.com/url/http%253A%252F%252Ftheurl.being.passed.com%252FsomeDir%252FsomeImage.png`. A bit convoluted but seems to work. – Fat Monk Dec 08 '16 at 16:29