Mobile app version of vmapp.org
Login or Join
Fox8124981

: .htaccess with Unicode and normal English I have the following .htaccess code: RewriteRule ^Indian-Patriot-Name/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+).*?$ indianpatriot.php?id=&lid=&name=

@Fox8124981

Posted in: #Apache #Htaccess #Unicode

I have the following .htaccess code:

RewriteRule ^Indian-Patriot-Name/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+).*?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]


Which allows me to view the result of the following link:

example.com/Indian-Patriot-Name/104/8/ச்வடன்ற்யவீர்%20சவர்க்கார்%20రాష్ట్రీయ%20சமரக்


However, when I want to view the following URL (not unicode):

example.com/Indian-Patriot-Name/104/8/abcd


I am unable to view the output as I'm getting a "file not found" error! However, if I change the directive/regex to the following then I can read the above (non-unicode) URL properly.

RewriteRule ^Indian-Patriot-Name-English/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ indianpatriot.php?id=&lid=&name= [L]




Q. How can I combine ([A-Za-z0-9-]+) and ([^x00-x7F]+) in the same rewrite statement?

I tried:

RewriteRule ^Indian-Patriot-Name-English/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+)+([A-Za-z0-9-]+)?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]


but I'm getting a "file not found" error again.



UPDATE: I tried the following:

RewriteRule ^Indian-Patriot-Name-English/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+ [A-Za-z0-9-]+)?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]


But I get an Internal Server Error:


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@sawarkar.in to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Fox8124981

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

RewriteRule ^Indian-Patriot-Name-English/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+ [A-Za-z0-9-]+)?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]


I get Internal Server Error ...


You have an erroneous space in the RewriteRule pattern. This will result in your "Internal Server Error" since spaces are delimiters in Apache directives. If you check your error log you'll probably see an error about "Invalid flags", since indianpatriot.php?id... will now be seen as the flags argument to the RewriteRule directive.

However, the suggestion by @PatrickMevzek in comments, to use alternation looks as if it should have worked. For example:

RewriteRule ^Indian-Patriot-Name-English/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([^x00-x7F]+|[A-Za-z0-9-]+)?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]


Note that your original regex that matches the unicode URL had an additional "catch everything else" pattern on the end: .*?. (Your regex that matches the non-unicode URL does not have this.) This does seem unusual. If this is required then you can simply omit the $ (end of string anchor) from the end of the pattern to do the same thing.

Note also, that [^x00-x7F] is a negated character class, that matches any character not in the byte range 00..7F (hex). In order to incorporate the latin alphabet, that falls in this range, then you could simply extend this range: [x00-xFF] - this is now a positive range that matches everything (which is no doubt more than you need, but you were probably matching more than you needed with the original regex).

However, this could perhaps be simplified. If you simply want to match anything (unicode or latin characters) at the end of the URL then ([^x00-x7F]+|[A-Za-z0-9-]+) (or even ([x00-xFF]+)) could be simplified to ([^/]+) (ie. anything except a slash). And, providing you don't also mind matching the underscore character, then [A-Za-z0-9-] could be reduced to [w-]. So, this becomes:

RewriteRule ^Indian-Patriot-Name-English/(w-]+)/([w-]+)/([^/]+)?$ indianpatriot.php?id=&lid=&name= [B,L,QSA]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme