mod_rewrite`重定向`如何?

mod_rewrite`重定向`如何?

我有 2 个 URL thinkingmonkey.methinkingmonkey.com它们的 IP 地址都是 127.0.0.1(又名 localhost)。

我想将所有请求重定向thinkingmonkey.comthinkingmonkey.me

<VirtualHost *:80>
    ServerAdmin [email protected]
    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 [email protected]
    ServerName thinkingmonkey.com
    DocumentRoot /mysite/happ

    Redirect thinkingmonkey.com  http://thinkingmonkey.me/

  #  Redirect / http://thinkingmonkey.me/ #have even tried this

    ServerAlias www.thinkingmonkey.com
    RewriteEngine on
</VirtualHost>

当我尝试访问时,thinkingmonkey.comurl 不会重定向到thinkingmonkey.me。浏览器地址栏中的 url 仍然是thinkingmonkey.com

我究竟做错了什么?

答案1

尝试

Redirect /  http://thinkingmonkey.me/

请注意,这只会重定向主页。要重定向所有页面:

RedirectMatch /(.*) http://thinkingmonkey.me/$1

http://httpd.apache.org/docs/2.2/mod/mod_alias.html

答案2

确保您NameVirtualHost *:80之前也指定了虚拟主机指令,然后Redirect / http://thinkingmonkey.me重试。

相关内容