1. 进入apache配置目录 /was/IHS/config
2. 修改配置文件 httpdf.conf
3. 在节点 #<VirtualHost *> </VirtualHost> 之后添加下面信息
NameVirtualHost *
<VirtualHost *>
DocumentRoot /was/IHS/htdocs
ServerName mss.cosmo-lady.com
<IfModule mod_dir.c>
DirectoryIndex rs.html
</IfModule>
</VirtualHost>
4. 在/was/IHS/htdocs 穿件rs.html 内容如下(域名跟自己情况修改)
<head>
<meta http-equiv="refresh" content="0;url=http://rs.cosmo-lady.com/ors">
</head>
5. 若没生效则重启apache
方式二:
公司里一个项目的网站已经运转了一段时间了,期间换过几次域名,现在想平稳的过渡到新的域名,这里就涉及到域名的自动跳转问题。
假设以前用过的域名是www.old.com,现在要用的新域名是www.new.com,那么现在的要求是任何类似www.old.com/xxx/yyy.htm的访问都自动跳转到www.new.com/xxx/yyy.htm上。
首先,因为类似yyy.htm这样的页面众多,所以不可能手动加代码来实现跳转,其次,因为要让浏览者感觉到域名的过渡,所以也不可能使用Rewrite来实现。这个时候就可以使用Apache的Redirect功能了。
实现方式很简单,只要修改httpd.conf相关代码就可以了,如下:
<VirtualHost *:80>
ServerName www.old.com
DocumentRoot /path/to/htdocs
......
<Directory "/path/to/htdocs">
RedirectMatch ^/(.*)$ http://www.new.com/$1
</Directory>
</VirtualHost>
最关键的代码都写在上面了,唯一要注意的是匹配就域名的时候使用的是“^/(.*)$”,而不是“^http://www.old.com/(.*)$”
补充:
根据网友的提示,搜索了一下,题目中的例子相应的应该写成:
RedirectMatch permanent ^/(.*)$ http://www.new.com/$1
<Directory "/path/to/htdocs">
RedirectMatch ^/(.*)$ http://www.new.com/index.html
</Directory>