如果你使用$1,你需要在你的 RewriteRule 中使用(). 尝试这个:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
这重定向http://olddomain.com/page.php到http://www.newdomain.com/page.php.
此外,如果可以有多个olddomains,请重定向任何不在的 url newdomain:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?newdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
这重定向http://notnewdomain.com/page.php到http://www.newdomain.com/page.php.
编辑:
这是我在http://htaccess.madewithlove.be的测试截图:
