301重定向到新域+将www重定向到非www

时间:2015-10-12 19:04:36

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

我有这个.htaccess代码,用于将带有www的URL重定向到不带www的URL:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

现在,我想通过301 http代码添加将整个网络重定向到另一个域的代码。但我不想让重定向循环。

我可以使用此代码:

RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

谢谢。

0 个答案:

没有答案