问题
I have developed this RewriteRule which has been working great, up until I discovered an issue.
This is the rule here:
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1/%2/%4.php -f
RewriteRule ^ /%1/%2/%4.php?id=%3 [QSA,L]
The URL format is like so: /home/service/ID/scriptname note that ID is dynamic and the RewriteRule does not take not of it when checking for the files existence.
But in this one scenario I found out, one of the IDs I'm using contains a '%2F' - which when decoded is translated to a forward slash (/) - And for some reason, the Rewrite rule when breaks because it thinks there's another directory.
My question is, why is %2F being decoded within the RewriteRule, and how can I engineer a solution? - Preferably other than a quick hack or changing the ID.
回答1:
I think you need to add the B flag in the rewrite rule, like this:
RewriteRule ^ /%1/%2/%4.php?id=%3 [QSA,L,B]
Check this link for more information.
来源:https://stackoverflow.com/questions/15497333/rewrite-rule-escaping-encoded-forward-slashes-within-url