views:

456

answers:

2

I have page which is redirected from htaccess. now I can pass the German characters as params

like

site.com/maörx/idasd

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9äÄöÖüÜéß\-]*)/?$ page.php?var=$1 [L]

it is working in the localhost . but not on the server.... server i am getting the same old issue(Error 404:Object not found!)

is the above code is correct for the server??

A: 

Unless there is something special about exactly these umlauts, you should use POSIX character classes in your regular expression such as [:alpha:], [:alphanum:], [:upper:] and [:lower:].

See, e.g., POSIX character classes in the Wikipedia article on regular expressions.

janko
+2  A: 

It depends on both character encodings (the one used in the .htaccess file and the one used for the requested URI) if your rule works. If both are the same, it should work.

Most user agents nowadays use either ISO 8859-1 or UTF-8 when encoding the URL for a request over HTTP. But UTF-8 will replace ISO 8859-1 sooner or later.

And as bobince noticed in the comments, Apache uses internally the single byte encoding ASCII when interpreting .htaccess files. So you might get problems when you use a multy byte encoding like UTF-8. But the following is encoding independed:

# for ISO 8859-1
RewriteRule ^([a-zA-Z0-9\xC4\xD6\xDC\xDF\xE4\xE9\xF6\xFC-]*)/?$ page.php?var=$1 [L]
# for UTF-8
RewriteRule ^(([a-zA-Z0-9-]|\xC3\x84|\xC3\x96|\xC3\x9C|\xC3\x9F|\xC3\xA4|\xC3\xA9|\xC3\xB6|\xC3\xBC)*)/?$ page.php?var=$1 [L]

But to avoid such construct, you could just exclude the slash and dot and validate the value later with PHP:

RewriteRule ^([^/.]*)/?$ page.php?var=$1 [L]
Gumbo
then why its happening only in server... i my local machine it is working.... :(
coderex
Maybe you’re using different encodings, either for the file or the URI.
Gumbo
+1, Apache deals with bytes, so the original rules would only work for ISO-8859-1 submissions, which are rare since URLs today are de facto UTF-8. Best avoid the issue on this layer by allowing any old character through; do any character checking you need to in the PHP script, it doesn't make sense to put logic like that in the web server layer as a rewrite.
bobince
thank s now it is working...
coderex