3

我正在尝试将所有访问者从我使用的旧域重定向到新域。

这是我使用的 .htaccess 文件的内容

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

其中http://foobar.com是新域。

上面的代码有效,但前提是访问者键入http://olddomain.com

我的意思是当访客输入

http://olddomain.com/terms.php他应该被重定向到http://foobar.com/terms.php

我希望无论访问者在旧域名之后键入什么(例如http://olddomain.com/privacy.phphttp://olddomain.com/users.php等),他们都会访问 http://foobar.com /不是http://foobar.com/privacy.php等。

4

1 回答 1

3
RewriteEngine On
RewriteCond %{HTTP_HOST} !^foobar\.com$ [NC]
RewriteRule .* http://foobar.com%{REQUEST_URI} [L,R=301]
于 2012-11-26T17:11:27.177 回答