Rewrite URL www.domain.com/ru_en/test/test to www.domain.com/ru/en/test/test

烂漫一生 提交于 2019-12-11 15:53:42

问题


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

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

The redirect must be done without changing the URL in the address bar.

Thanks for your help


回答1:


Can u try with this?

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; 

EDIT: Adding $server_name instead of URL. This will made it universal.



来源:https://stackoverflow.com/questions/57327340/rewrite-url-www-domain-com-ru-en-test-test-to-www-domain-com-ru-en-test-test

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