繁体   English   中英

301重定向到新域和新名称文件夹

[英]301 redirect to new domain and new name folder

我要更改我的域名,但也需要更改 url 结构上的一个文件夹名称。 我希望“www.example.com/name”成为“new-example.com/new-name”。

我有这个 .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]

但此代码删除重定向链接上的“名称”文件夹。 如何更改文件夹名称而不将其删除?

这行得通吗?

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]

试试这个规则作为你的第一条规则:

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]

在测试此更改之前清除浏览器缓存。

暂无
暂无

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

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