【问题标题】:301 Redirect all pages of site to homepage301 将网站所有页面重定向到首页
【发布时间】:2018-01-31 20:18:24
【问题描述】:

我有一个业务正在关闭的客户站点。他们希望暂时保持他们的网站正常运行,但他们还希望转到任何以前的 URL,自动将人们重定向到主页。

我在 .htaccess 中尝试了多种方法,如下所示:

RedirectMatch permanent .* http://www.hotskitchen.com

但是没有任何效果。唯一发生的事情是样式表消失了。除了从单个页面编写大量 301 重定向之外,我还能做些什么来使此重定向正常工作?

这是完整的 .htaccess

# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteRule .* - [E=W3TC_ENC:_gzip]
    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
    RewriteRule .* - [E=W3TC_PREVIEW:_preview]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    RewriteCond "%{DOCUMENT_ROOT}/wordpress/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/wordpress/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

# END WordPress

Redirect 301 /about http://www.hotskitchen.com/about-hots-kitchen/
Redirect 301 /about/our-concept http://www.hotskitchen.com/about-hots-kitchen/our-concept/
Redirect 301 /about/the-people http://www.hotskitchen.com/about-hots-kitchen/the-people/

【问题讨论】:

  • Redirect 301 / http://www.hotskitchen.com/ 应该可以工作。如果它不起作用,那么您的 .htaccess 可能没有启用。
  • 不。那也没用。并且 .htaccess 已启用。我知道,因为我之前在那里为我重定向的三个页面设置了重定向。
  • 好的,你能出示完整的 .htaccess 文件吗
  • 我必须把它放在主帖中。由于篇幅原因,这里不让我这样做。
  • 不。没用。我得到的只是去掉了 CSS 的同一个网页。第二种方法重定向到hotskitchen.com/wordpress/wp-content/cache/page_enhanced/…

标签: .htaccess redirect


【解决方案1】:

应该为 .htaccess 解决问题:

RedirectMatch 301 ^/ http://www.hotskitchen.com/

就个人而言,我更喜欢 mod_rewrite 在使用 Apache 时实现这一点:

RewriteEngine On
Redirect 301 / http://www.hotskitchen.com/

更好的是,在 nginx 中为该特定域名提供服务器侦听器,它适用于任何路径:

server {
    listen 80;

    server_name www.oldwebsite.com;

    return 301 http://www.hotskitchen.com/;
}

【讨论】:

  • 我试了第一个,完全没用。第二个......只是坐在那里加载了很长时间,它终于没有重定向,事实上,所有的CSS样式都消失了。第三个......好吧,那会进入.htaccess吗?事情是它从 hotskitchen.com 转到 hotskitchen.com。换句话说,除了 hotskitchen.com 主页之外的所有页面都应该重定向到主页。
猜你喜欢
  • 2012-12-21
  • 1970-01-01
  • 2015-01-14
  • 2013-02-21
  • 2015-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多