【问题标题】:301 rediect home page to new domain dealing with 'www / no www' and '/index.html'301 将主页重定向到处理“www / no www”和“/index.html”的新域
【发布时间】:2012-11-21 12:44:51
【问题描述】:

正在移动网站的网址,因此我们设置了从每个页面到新网站上相应页面的 301 重定向。我们使用的语法是:

redirect 301 /about-us.html http://newiste.co.uk/about-us.html

我遇到的问题是如何将旧主页 - http://oldsite.co.uk 发送到 http://newsite.co.uk - 因为主页位于 domain.co.uk 没有 /index.html 也有类似的问题万维网。与非 www。

像这样在旧域上配置我的 .htaccess 文件是正确的方法吗?

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://oldsite.co.uk/$1 [R=301,L]
order deny,allow

redirect 301 / http://newsite.co.uk
redirect 301 /about-us.html http://newsite.co.uk/about-us.html
redirect 301 /contact-us.html http://newsite.co.uk/contact-us.html
redirect 301 /bespoke-furniture.html http://newsite.co.uk/bespoke-furniture.html
redirect 301 /how-we-work.html http://newsite.co.uk/discovery.html

【问题讨论】:

  • 您只需要将特定(列出的)网址重定向到新网站吗?

标签: .htaccess http-status-code-301


【解决方案1】:

要重定向根文档,可以使用以下重写规则:

RewriteRule ^/?$ http://newsite.co.uk/ [R=301,L]

也对您的评论:

RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]

端口号绝不是 HTTP_HOST 变量的一部分,最有效的是尽可能避免使用正则表达式:

RewriteCond %{HTTP_HOST} =www.oldsite.co.uk [NC]

您的代码 redirect 301 / http://newsite.co.uk 将重定向所有内容,而不仅仅是根 /

【讨论】:

  • 谢谢,所以我会像这样 RewriteRule ^/?$ newsite.co.uk [R=301,L] redirect 301 /about-us.html newsite.co.uk/about-us.html 并有一个新的开始重定向每页301?
  • @sam 如果您只需要重定向 一些 页面,那么是的,您需要按照现在的方式列出它们。只需删除redirect 301 / http://newsite.co.uk 并添加引用的RewriteRule
  • 对不起,请忽略此评论
猜你喜欢
  • 2014-08-28
  • 2011-04-01
  • 2015-02-24
  • 2013-06-26
  • 2018-05-01
  • 2021-03-23
  • 1970-01-01
  • 2017-05-03
  • 2014-04-09
相关资源
最近更新 更多