将网址www.domain.com/ru_en/test/test重写为www.domain.com/ru/en/test/test
问题描述:
在检测到ru_ru或ru_en或cn_cn或cn_en的情况下,我想通过用下划线_代替下划线_来重写另一个URL.
I want to rewrite an url to an other by replacing the underscore _ with slash / in the case of detecting ru_ru or ru_en or cn_cn or cn_en
我正在使用nginx,我想使用重写来定义规则或重写
I m using nginx and I want to use the rewrite to define the rule or the rewrite
www.domain.com/ru_en/test/test to www.domain.com/ru/en/test/test
www.domain.com/ru_ru/test/ to www.domain.com/ru/ru/test/
www.domain.com/cn_en/test/test to www.domain.com/cn/en/test/test
www.domain.com/cn_cn/go to www.domain.com/cn/cn/go
必须在不更改地址栏中URL的情况下完成重定向.
The redirect must be done without changing the URL in the address bar.
感谢您的帮助
答
您可以尝试吗?
rewrite ^/ru_en/(.*)$ http://$server_name/ru/en/$1 permanent;
rewrite ^/ru_ru/(.*)$ http://$server_name/ru/ru/$1 permanent;
rewrite ^/cn_en/(.*)$ http://$server_name/cn/en/$1 permanent;
rewrite ^/cn_cn/(.*)$ http://$server_name/cn/cn/$1 permanent;
添加$ server_name而不是URL.这将使它变得通用.
Adding $server_name instead of URL. This will made it universal.