.htaccess 301除主页外所有页面的重定向

.htaccess 301除主页外所有页面的重定向,.htaccess,.htaccess,我试图实现的是对一个域的所有页面/资源(除了站点的根)进行301重定向,然后每个页面都应该从www.example.com/example.com移动到old.example.com 我不是htaccess大师,但这是我提出的解决方案 RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteCond !^$ [NC] RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L] 但似乎不起

我试图实现的是对一个域的所有页面/资源(除了站点的根)进行301重定向,然后每个页面都应该从www.example.com/example.com移动到old.example.com

我不是htaccess大师,但这是我提出的解决方案

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

但似乎不起作用

您在重写时丢失了测试字符串

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]