首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >301将旧站点重定向到新站点,维护一些文件夹结构,但不是全部

301将旧站点重定向到新站点,维护一些文件夹结构,但不是全部
EN

Stack Overflow用户
提问于 2013-09-03 23:01:11
回答 1查看 116关注 0票数 1

因此,我正在将我的站点从一个子域“移动”到根域上的一个子文件夹中,在这个过程中,我不得不改变一些子目录结构。这使得重定向对于像我这样几乎没有htaccess知识的人来说有点困难。

一些结构对于架构中更深层的东西是相同的(它本质上是一个目录网站),但有些东西需要移动。以下是我到目前为止创建的内容:

代码语言:javascript
复制
Options +FollowSymlinks 
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/for-sale$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/search$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/for-sale-details$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/details$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/buyer-registration
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/buyer-registration [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/advertise-with-us
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/advertise-with-us [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/favourites
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/favourites [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/saved-searches
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/saved-searches [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/system$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/system$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/ [R=301,L]

我想要发生的一个例子是

代码语言:javascript
复制
http://subdomain.example.com/for-sale-details/35141_xml_bvi0009154/gensac-gironde 

重定向到

代码语言:javascript
复制
http://www.example.com/property-for-sale/details/35141_xml_bvi0009154/gensac-gironde 

诸若此类。

从本质上讲,上述代码末尾没有$的重定向是独立的页面,在此之后没有更多的子目录。任何在末尾带有$的内容都意味着还有更多的目录层,但是在这之后的任何内容都应该保留在新URL的末尾。

任何帮助都将不胜感激!是的,当涉及到这类事情时,我是一个完全的新手,所以请对我友好点:)

EN

回答 1

Stack Overflow用户

发布于 2013-09-04 03:36:59

%{HTTP_HOST}变量是来自请求的“”报头,其中只有包含主机名,而不像/for-sale那样包含路径信息。因此,您只与此匹配,并且您的任何规则都不会起作用,因为您正在尝试与URI路径进行匹配。

因此,您的所有规则都需要如下所示:

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^for-sale/(.*)$ /property-for-sale/search/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^for-sale-details/(.*)$ /property-for-sale/details/$1 [R=301,L]

等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18595534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档