Home > other >  .htaccess rewrite url with letters öäå and passing variables
.htaccess rewrite url with letters öäå and passing variables

Time:03-23

Lets say survey name is test.

When completing form it redirects to www.example.com/survey_thank_you.php?survey_name=test

then rewrites it to www.example.com/test/thank_you and it works as inteded.

But because here we use öäå the issue emerge. If survey name is testä, it redirects allright but rewrites it to www.example.com/test%C3%A4/thank_you (this works) and it should rewrite to www.example.com/testä/thank_you

also if go straight to www.example.com/testä/thank_you it works.

htaccess:

Options  FollowSymLinks
Options -MultiViews
RewriteEngine on
AddCharset UTF-8 .php
AddDefaultCharset utf-8


RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^survey_name=(.*)/?$
RewriteRule ^survey_thank_you\.php$ /%1/thank_you [R,L,QSD]
RewriteRule ^(.*)/thank_you$ survey_thank_you.php?survey_name=$1 [L,NC,QSA]


RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(.*)/?$ survey_form.php?survey_name=$1 [L,NC,QSA]

If i change (.*) to ([0-9a-zA-Z] ) it rewrites it allright /testä/thank_you but then i get error 404. Any suggestions much appreciated.

CodePudding user response:

test%C3%A4 would be the result of double URL encoding. One level decoded, leaves testä.

You can use the NE flag to try and avoid double encoding in this place, https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne

  • Related