Martti Laine
Martti Laine

Reputation: 12985

Adding encoded chars to the url breaks htaccess

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

Upvotes: 3

Views: 1790

Answers (2)

Tim Stone
Tim Stone

Reputation: 19169

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

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

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.

Upvotes: 2

Related Questions