301重定向到新的领域和新名称的文件夹 [英] 301 redirect to new domain and new name folder
本文介绍了301重定向到新的领域和新名称的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要改变我的域名,但也需要改变和URL结构一个文件夹名称。我想www.example.com/name成为new-example.com/new-name。
I'm going to change my domain name but also need to change and one folder name on url structure. I want "www.example.com/name" to become "new-example.com/new-name".
我有这样的code代表的.htaccess:
I have this code for .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(?:name/?)?(.*)$ http://new-example.com/$1 [L,R=301,NC,NE]
但这种code移除链接重定向名文件夹中。我如何更改文件夹的名称,而不是删除它?
but this code remove "name" folder on redirected links. How can i change folder name and not remove it?
推荐答案
试试这个规则是你的第一个规则:
Try this rule as your very first rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^name(/.*)?$ http://new-example.com/new-name$1 [L,R=301,NC,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301,NE]
测试此更改之前清除浏览器缓存。
Clear your browser cache before testing this change.
这篇关于301重定向到新的领域和新名称的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文