Regular expression to match russian, allow all cyrillic characters in .htaccess

后端 未结 1 1793
野性不改
野性不改 2021-01-20 00:39

How do i redirect url with russian slug to specific php page. For example I have this url.

   http://www.example.com/основной-момент.htm

an

相关标签:
1条回答
  • 2021-01-20 01:14

    If it's allowed in your server you could try something like this for the specific page in your .htaccess file:

    RewriteEngine On
    RewriteRule ^основной-момент.htm$ category.php?slug=ru
    

    In Regex if the character set is enabled on your server you should be able to use the range for the characters:

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

    To capture the phrase you would use this (just like English):

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

    Another way is by detecting the language

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

    Additionally if you're using a dynamic language on the server you should be able to use the REQUEST_URI var for parsing and determining the intended language as Apache serves the content and programming languages (like PHP or Perl) can do more with parsing.

    0 讨论(0)
提交回复
热议问题