htaccess 重定向网站 [英] htaccess redirect website
问题描述
我正在尝试将所有访问者从我使用的旧域重定向到新域.
I'm trying to redirect all my visitors from the old domain that I use to the new one.
这是我使用的 .htaccess 文件的内容
Here is the content of the .htaccess file that I use
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !foobar.com$ [NC]
RewriteRule ^(.*)$ http://foobar.com/$1 [L,R=301]
其中 http://foobar.com 是新域.
以上代码有效,但前提是访问者输入了 http://olddomain.com.
The code above works but only if the visitor type http://olddomain.com.
我的意思是当访问者输入时
What I mean is when the visitor types
http://olddomain.com/terms.php 他应该被重定向到 http://foobar.com/terms.php
我希望访问者在旧域名后输入任何内容(例如 http://olddomain.com/privacy.php、http://olddomain.com/users.php 等)他们去http://foobar.com/ 不要http://foobar.com/privacy.php 等
I want that whatever the visitor types after the old domain name (like http://olddomain.com/privacy.php, http://olddomain.com/users.php, etc) they go to http://foobar.com/ not to http://foobar.com/privacy.php etc.
推荐答案
RewriteEngine On
RewriteCond %{HTTP_HOST} !^foobar\.com$ [NC]
RewriteRule .* http://foobar.com%{REQUEST_URI} [L,R=301]
这篇关于htaccess 重定向网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!