Regular expression to match Russian, allow all Cyrillic characters in .htaccess

How to redirect a Russian slug URL to a specific php page. For example, I have this url.

http://www.example.com/-.htm 

and want to redirect it to .htaccess

  http://www.example.com/category.php?slug=<russian slug> 
+4
source share
1 answer

If allowed on your server, you can try something like this for a specific page of your .htaccess file:

 RewriteEngine On RewriteRule ^-.htm$ category.php?slug=ru 

In Regex, if the character set is enabled on your server, you can use a range for characters:

 RewriteRule ^([A---]+)\.htm$ category.php?slug=ru 

To record a phrase, you will use it (as in English):

 RewriteRule ^([A---]+)\.htm$ category.php?slug=$1 

Another way is language detection

 #For users with Russian as their primary browsing language RewriteCond %{HTTP:Accept-Language} ^ru [NC] RewriteRule .* category.php?slug=ru 

In addition, if you use a dynamic language on the server, you can use REQUEST_URI var to parse and determine the intended language, since Apache serves content and programming languages โ€‹โ€‹(like PHP or Perl), can do more with parsing.

+3
source

Source: https://habr.com/ru/post/1484984/


All Articles