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

坚强是说给别人听的谎言 提交于 2020-01-24 05:30:05

问题


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

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

and want to redirect to this one in .htaccess

   http://www.example.com/category.php?slug=<russian slug>

回答1:


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.



来源:https://stackoverflow.com/questions/16978182/regular-expression-to-match-russian-allow-all-cyrillic-characters-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!