1

I have URL with an encoded slash (%2F) and I cannot get rewrite rules to catch this correctly.

My URL is:

http://example.com/some-path/description%2Frest-of-description/1101

I've tried rewrites like:-

# is the %2F interpreted as a path separator
RewriteRule ^some-path/(.*)/(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L]
# or is it as an encoded string
RewriteRule ^some-path/(.*)%2F(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L]
# or even double encoded
RewriteRule ^some-path/(.*)%252F(.*)/(.*)$ /villas/$1-$2/$3 [B,R=301,NE,L]

I've also tried adding QSA to above.

There is a similar question on SO here but it's IIS and .NET based

I'm running LAMP stack

Community
  • 1
  • 1
ChrisB
  • 611
  • 11
  • 24
  • 2
    Check this: http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes – Nikhil Dec 24 '15 at 11:22
  • @Nikhil You should add that as an answer (with a bit more info). – MrWhite Dec 24 '15 at 11:32
  • I tried adding AllowEncodedSlashes On to vhosts and get 500 on all requests ... apache 2.4 – ChrisB Dec 24 '15 at 11:39
  • Just to confirm, with `AllowEncodedSlashes Off` (default) do you get a _system generated_ 404 (ie. the server's default 404, not a custom 404 page)? – MrWhite Dec 24 '15 at 12:07

1 Answers1

3

For security reasons Apache deny %2F. See urlencoded Forward slash is breaking URL

You can turn off this with AllowEncodedSlashes directive in your server config.

But it would be better if you encode the URL if you have control of this part of the code.

Community
  • 1
  • 1
NBK
  • 58
  • 6
  • thx but can't get it to work. Gives a 500 if placed either in httpd.conf or the vhosts. Maybe an OSX error (my dev machine) ... will try on a linux machine later. – ChrisB Dec 24 '15 at 11:52
  • Look if this post brings some help: http://stackoverflow.com/questions/4390436/need-to-allow-encoded-slashes-on-apache – NBK Dec 24 '15 at 11:57
  • Yes, that's got it - thx! Just for the record, I can't encode the urls differently as they are already in google index. In fact, in trying to remap them, I came across this error. – ChrisB Dec 24 '15 at 13:31