.htaccess UTF 8 URL Redirection

I am trying to redirect all non-domain requests to www while keeping the request URI.

I use this in my .htaccess file to redirect:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302] 

The problem is that when I have a query like this:

example.com/search/?name=läkare

It redirects to:

 www.example.com/search/?name=l%25C3%25A4kare 

Which type is incorrect, it encodes it twice. I check this as follows:

 <?php echo rawurlencode('läkare');//outputs l%C3%A4kare echo "\n"; echo rawurldecode('l%25C3%25A4kare');//outputs l%C3%A4kare echo "\n"; echo rawurldecode(rawurldecode('l%25C3%25A4kare'));//outputs läkare 

Why does he code it twice and how can I make him do it? I'm fine with 1 encoding, but 2 is too much.

+6
source share
1 answer

For your rule, you will need the NE (no escape) rewrite flag. This will prevent double escaping of the escaped query string:

 RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE] 
+7
source

All Articles