Reputation: 1257
I am trying to rewrite an url with GET-data from a form. This works fine when committing strings with only English letters. But when I commit Norwegian characters (this is a Norwegian page), only the non-rewritten url is displayed. My mod_rewrite
sentences looks like this:
RewriteCond %{REQUEST_URI} /resultpage.php$
RewriteCond %{QUERY_STRING} ^querystring=([a-zæøåäëöA-ZÆØÅÄËÖ0-9-\+]+)$
RewriteRule ^(.*)$ /sok/%1? [R=301,L]
RewriteRule ^sok/(.*)$ /resultpage.php?querystring=$1&a=1 [L]
I use Norwegian characters in url's not posted from a form and this works great.
Any suggestions?
Upvotes: 0
Views: 514
Reputation: 655299
I would use [^&]
instead:
RewriteCond %{REQUEST_URI} ^/resultpage\.php$
RewriteCond %{QUERY_STRING} ^querystring=([^&]+)$
RewriteRule ^resultpage\.php$ /sok/%1? [R=301,L]
And you can still simplify it:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /resultpage\.php\?querystring=([^&\s]+)\s
RewriteRule ^resultpage\.php$ /sok/%1? [R=301,L]
Using this solution you even could leave the a=1
flag of the second RewriteRule
away.
Upvotes: 1
Reputation: 12167
The Norwegian characters are likely to be URL encoded.
I can't see from the docs how mod rewrite is going to handle these.
At a guess
RewriteCond %{QUERY_STRING} ^querystring=([a-zA-Z0-9-+%]+)$
May work as it will pick up the url encoded extended chars, but it will allow any char, not just the set you want. You could always fix this at the application layer.
Upvotes: 1