1

I have a relatively simple htaccess redirect that redirects all urls to a php file designed to handle urls with the exception of 3 specific directories:

Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{REQUEST_URI} !^/system [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/downloads [NC]
RewriteRule (.*)$ ./system/page.php?url=$1

And it works great... almost. For normal characters it works great but as soon as I introduce special characters that have been url encoded it seems to struggle a bit and I have no idea why.

In page.php I have a simple line of code to display the url:

echo $_GET['url'];

The following is echoed out from these various urls:

mydomain.com/test -> echos "test" (which is correct)
mydomain.com/tt%23tt -> echos "tt" (the desired echo would be tt%23tt)
mydomain.com/tt%25tt -> echos "tt%tt" (the desired echo would be tt%25tt)

Basically I am trying to get the string exactly as it appears in the url and let php handle it from there but I'm pretty terrible at htaccess.

Any help would be great, thanks!

1 Answer 1

1

Try matching against the actual request instead of the decoded URI:

Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{REQUEST_URI} !^/system [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/downloads [NC]
RewriteCond %{THE_REQUEST} \ /+([^\ \?]*)
RewriteRule (.*)$ ./system/page.php?url=%1 [L,B]

The %{THE_REQUEST} var is the first line of the request, so the request isn't decoded, then you need the B flag so that the % doesn't get decoded in the query string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.