问题
Here's my code:
RewriteEngine on
RewriteRule page/(.*) index.php?url=$1 [NC]
When I access page/http://google.com/ = works just fine
When I access page/http%3A%2F%2Fgoogle.com%2F = server reports 404
Martti Laine
回答1:
Apache returns a (somewhat non-intuitive) 404 in cases when you have encoded slashes in the request, but do not have AllowEncodedSlashes set to on. To confirm this is the case, check your error log, which likely contains an entry like this:
found %2f (encoded '/') in URI (decoded='/page/http://google.com/'), returning 404
回答2:
I believe you need the B (escape) flag:
RewriteRule page/(.*) index.php?url=$1 [NC,B]
That will escape the back-reference ($1) before adding it to the replace string.
来源:https://stackoverflow.com/questions/3388210/adding-encoded-chars-to-the-url-breaks-htaccess