Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess RewriteRule to redirect http to https messes up % escaped parameters in URL

I'm using something similar to the following in my .htaccess file to redirect all http requests to https:

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

That works, except for a situation when a URL is passed with escaped parameters, as such:

http://www.example.com/download.php?go=app%20name

when redirected, it is mistakenly escaped again into:

https://www.example.com/download.php?go=app%2520name

How do I fix this?

like image 625
c00000fd Avatar asked Feb 24 '26 14:02

c00000fd


1 Answers

Use NE or noescape flag in your rule:

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Make sure to clear your browser cache before testing the change.

like image 184
anubhava Avatar answered Feb 27 '26 07:02

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!