我有2个网址说thinkingmonkey.me
和thinkingmonkey.com
都有ip-address 127.0.0.1(A.K.A localhost)。
我想将任何请求重定向到thinkingmonkey.com
到thinkingmonkey.me
。
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /mysite
ServerName thinkingmonkey.me
ServerAlias www.thinkingmonkey.me
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
Options -Indexes +FollowSymLinks
RewriteEngine On
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName thinkingmonkey.com
Redirect thinkingmonkey.com http://thinkingmonkey.me/
# Redirect / http://thinkingmonkey.me/ #have even tried this
ServerAlias www.thinkingmonkey.com
RewriteEngine on
</VirtualHost>
当我尝试访问thinkingmonkey.com
时,该网址未被重定向到thinkingmonkey.me
。浏览器地址栏中的网址仍为thinkingmonkey.com
。
我做错了什么?
答案 0 :(得分:1)
mod_rewrite被认为更好,更强大,可以处理这些重写。您可以使用以下代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*\.)?thinkingmonkey\.com$ [NC]
RewriteRule ^ http://%1thinkingmonkey.me%{REQUEST_URI} [L,R=301]
如果您真的非常想使用mod_aias,可以将此行添加到VirtualHost
的{{1}}部分:
thinkingmonkey.com
答案 1 :(得分:0)
试试这个:
RewriteEngine On
RewriteCond %{HTTP_HOST} !.*thinkingmonkey\.me$
RewriteRule ^/(.*)$ http://thinkingmonkey.me/$1 [R]