问题
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