首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要在.htaccess中为不同的域和不同的目录结构创建301重定向

问我需要在.htaccess中为不同的域和不同的目录结构创建301重定向
EN

Stack Overflow用户
提问于 2014-02-22 06:03:48
回答 1查看 82关注 0票数 0

我用RedirectMatch试过了,但是我的代码不工作。我的语法可能不正确。

下面是我的代码:

代码语言:javascript
复制
RedirectMatch 301 ^oldsite.com/guides/$ http://newsite.com/destinations/city-guides/
RedirectMatch 301 ^oldsite.com/show/$ http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/destinations/$ http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/concept.html http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/format.html http://newsite.com/tv-show/format/
RedirectMatch 301 ^oldsite.com/about.html http://newsite.com/about/
RedirectMatch 301 ^oldsite.com/contact.html http://newsite.com/contact/

前三行我希望那些旧目录中的任何文件都转到新目录的根目录。最后四个是特定的页面到页面重定向。

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2014-02-22 06:07:52

您与RedirectMatch中的域名不匹配。仅匹配请求URI。

在旧网站的.htaccess上试试这个:

代码语言:javascript
复制
RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ - [L]

RewriteRule ^guides/$ http://newsite.com/destinations/city-guides/ [L,R=301]
RewriteRule ^show/$ http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^destinations/$ http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^concept.html http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^format.html http://newsite.com/tv-show/format/ [L,R=301]
RewriteRule ^about.html http://newsite.com/about/ [L,R=301]
RewriteRule ^contact.html http://newsite.com/contact/ [L,R=301]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21946113

复制
相关文章

相似问题

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