PHP User
PHP User

Reputation: 2422

allow any character in htaccess query string validation (non-English characters)

I'm having this htaccess rule

RewriteRule ^page/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/(.*)/([0-9a-zA-Z_-_]+)
/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ page.php?lang=$1&search=$2&state_type=$3&city=$4
&stats=$5&area=$6&cost=$7 [NC,L]

The fourth query string is in Arabic and I want to allow any characters as long as [0-9a-zA-Z_-] will validate against English characters only. When I use (.*) it allows any English characters but when I insert Arabic characters I get a 404 error. So how to allow any characters in htaccess validation rule to get Arabic values?

[UPDATE] Changed the htaccess rule to:

RewriteRule ^page/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)$ page.php?lang=$1&search=$2&
state_type=$3&city=$4&stats=$5&area=$6&cost=$7 [NC,L]

Now I don't get the 404 error but when I echo the query string value (which is in Arabic) I get empty value and when I change it to English it works fine. I've tried to change all the query string values to Arabic and got the same result: empty as it's not there at all.

Upvotes: 0

Views: 1218

Answers (1)

Walf
Walf

Reputation: 9308

Try

RewriteRule ^page/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ page.php?lang=$1&search=$2&state_type=$3&city=$4&stats=$5&area=$6&cost=$7 [B,NC,L]

. is too greedy so just look for anything that's not a /. The B flag turns decoded characters back into escaped ones suitable for a query string.

Upvotes: 2

Related Questions