我有一个客户网站,他的业务正在关闭。他们想暂时保留他们的网站,但他们还想要的是,转到任何以前的网址,会自动将人们重定向到主页。
我已尝试过多种方法在.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/
答案 0 :(得分:0)
应该为.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/;
}