.htaccess htaccess如何重定向所有页面,但不重定向根目录

.htaccess htaccess如何重定向所有页面,但不重定向根目录,.htaccess,redirect,.htaccess,Redirect,我需要htaccess 301重定向的帮助 我有一个网站www.site.com,但我需要将所有页面更改为www.newsite.com,但我不想移动www.site.com(获取页面信息) 例如: www.site.com (not move) index of to put then a template or message www.site.com/2012/08/page.html move to www.newsite.com/2012/08/page.html www.site.

我需要htaccess 301重定向的帮助

我有一个网站www.site.com,但我需要将所有页面更改为www.newsite.com,但我不想移动www.site.com(获取页面信息)

例如:

www.site.com (not move) index of to put then a template or message

www.site.com/2012/08/page.html move to www.newsite.com/2012/08/page.html
www.site.com/tag/keyword/ move to www.newsite.com/tag/keyword/
www.site.com/category/general/ move to www.newite.com/category/general/

我怎么能做到?感谢
www.site.com
上的主机通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在
文档根目录下的
.htaccess
中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteRule ^.+$ http://www.newsite.com%{REQUEST_URI} [L,R=301]

您可以尝试使用mod_alias'
RedirectMatch
在URI中强制执行重定向。在site.com文档根目录中的htaccess文件中,添加:

RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1
这将使它在
http://www.site.com/
将被重定向,但只是
http://www.site.com/
将不会。但是,
http://www.site.com/index.html
将被重定向。如果这是一个问题,您可以使用mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.html$
# and whatever else you don't want redirected
RewriteRule ^(.*)$ http://www.newsite.com/$1 [L,R=301]

@阿努巴瓦:在这个网站上永远是我的救世主。非常感谢你。使用这些资源也会被重定向。这是对的,但可能不是op想要的。