简体   繁体   English

.htacess重定向301无法正常工作

[英].htacess redirect 301 doesn't work properly

I have issue to redirect 301 URLs, 我在重定向301 URL时遇到问题,

I want to redirect from fr.example.com/fr to www.example.com/fr-ch the rest of the URL doesnt have always same structure but htaccess redirect to same structure, exemple: 我想从fr.example.com/fr重定向到www.example.com/fr-ch,URL的其余部分并不总是具有相同的结构,但是htaccess重定向到相同的结构,例如:

RewriteCond %{HTTP_HOST} ^fr\. [NC]
Redirect 301    /fr   https://www.example.com/fr-ch         
Redirect 301    /fr/coffee/arabica-robusta  https://www.example.com/fr-ch/ccc/arabica-robusta

what I get as result is redirect to https://www.example.com/fr-ch/coffee/arabica-robusta 结果是重定向到https://www.example.com/fr-ch/coffee/arabica-robusta

and not to 而不是

https://www.example.com/fr-ch/ccc/arabica-robusta https://www.example.com/fr-ch/ccc/arabica-robusta

Am I missing something ?? 我错过了什么吗?

You need to redirect EXACTLY /fr, so you need to add ^ in the beginning and $ at the end. 您需要完全重定向/ fr,因此需要在开头添加^ ,在结尾添加$

So this should work : 所以这应该工作:

Redirect 301    ^/fr$   https://www.example.com/fr-ch         

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM