Apache 如何重写“重定向”?
我有两个URL,分别是Apache 如何重写“重定向”?,apache,mod-rewrite,url-rewriting,apache2,httpd.conf,Apache,Mod Rewrite,Url Rewriting,Apache2,Httpd.conf,我有两个URL,分别是thinkingmonkey.me和thinkingmonkey.com都有ip地址127.0.0.1(也称为本地主机) 我想将所有请求重定向到thinkingmonkey.com到thinkingmonkey.me <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /mysite ServerName thinkingmonkey.m
thinkingmonkey.me
和thinkingmonkey.com
都有ip地址127.0.0.1(也称为本地主机)
我想将所有请求重定向到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>
服务器管理员webmaster@dummy-host.example.com
DocumentRoot/mysite
ServerName thinkingmonkey.me
服务器别名www.thinkingmonkey.me
错误日志/dummy-host.example.com-error\u日志
CustomLog日志/dummy-host.example.com-access\u日志公用
选项-索引+FollowSymLinks
重新启动发动机
服务器管理员webmaster@dummy-host.example.com
ServerName thinkingmonkey.com
重定向thinkingmonkey.comhttp://thinkingmonkey.me/
#重定向/http://thinkingmonkey.me/ #我甚至试过这个
ServerAlias www.thinkingmonkey.com
重新启动发动机
当我尝试访问thinkingmonkey.com
时,url不会重定向到thinkingmonkey.me
。浏览器地址栏中的url仍然是thinkingmonkey.com
我做错了什么?试试这个:
RewriteEngine On
RewriteCond %{HTTP_HOST} !.*thinkingmonkey\.me$
RewriteRule ^/(.*)$ http://thinkingmonkey.me/$1 [R]
文档:mod_rewrite被认为是处理这些重写的更好、更强大的工具。您可以使用以下代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*\.)?thinkingmonkey\.com$ [NC]
RewriteRule ^ http://%1thinkingmonkey.me%{REQUEST_URI} [L,R=301]
如果你真的想使用mod_aias,你可以把这一行放在thinkingmonkey.com
的VirtualHost
部分:
Redirect 301 / http://thinkingmonkey.me/