views:

134

answers:

3

I am trying to rewrite an url with get-data from at form. This is working all good when committing strings with only English letters. But when commit Norwegian charachters (this is a Norwegian page), only the non-rewriten 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 charachters in url's not posted from a form and this works great.

Any suggestions?

+1  A: 

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.

Jeremy French
A: 

Thank you! That helped a lot :)

jorgen
+1  A: 

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.

Gumbo