问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/34451993/htaccess-howto-rewrite-an-encoded-slash-in-url