在 httpd 中将一个域名转发到另一个域名
虚拟主机世界近期更换了域名,新域名为 www.wbhw.com, 更加简短好记。这时需要将原来的域名 webhosting-world.com, 以及论坛所在地址 webhosting-world.com/forums/ 定向到新的域名,以便用户可以找到,并且使原来的论坛 URL 继续有效而不出现 404 未找到,比如原来的 http://www. webhosting-world.com/forums/-f60.html, 让它在新的域名下继续有效,点击后转发到 http://bbs.wbhw.com/-f60.html, 这就需要用 apache 的 Mod_rewrite 功能来实现。
在< virtualhost> 中添加下面的重定向规则:
RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule /forums/(.*) http://bbs.wbhw.com/{GetProperty(Content)} [R=permanent,L]
# Redirect webhosting-world.com to wbhw.com
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule /(.*) http://www.wbhw.com/{GetProperty(Content)} [R=permanent,L]
添加了上面的规则以后, 里的全部内容如下:
< virtualhost *:80>
ServerAlias webhosting-world.com
ServerAdmin admin@webhosting-world.com
DocumentRoot /path/to/webhosting-world/root
ServerName www.webhosting-world.com
RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule /forums/(.*) http://bbs.wbhw.com/{GetProperty(Content)} [R=permanent,L]
# Redirect webhosting-world.com to wbhw.com
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule /(.*) http://www.wbhw.com/{GetProperty(Content)} [R=permanent,L]
< /virtualhost>
URL重定向例子一:
1.http://www.zzz.com/xxx.php-> http://www.zzz.com/xxx/
2.http://yyy.zzz.com-> http://www.zzz.com/user.php?username=yyy 的功能
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.zzz.com
RewriteCond %{REQUEST_URI} !^user\.php$
RewriteCond %{REQUEST_URI} \.php$
RewriteRule (.*)\.php$ http://www.zzz.com/{GetProperty(Content)}/ [R]
RewriteCond %{HTTP_HOST} !^www.zzz.com
RewriteRule ^(.+) %{HTTP_HOST} [C]
RewriteRule ^([^\.]+)\.zzz\.com http://www.zzz.com/user.php?username={GetProperty(Content)}
例子二:
/type.php?typeid=* --> /type*.html
/type.php?typeid=*&page=* --> /type*page*.html
RewriteRule ^/type([0-9]+).html$ /type.php?typeid={GetProperty(Content)} [PT]
RewriteRule ^/type([0-9]+)page([0-9]+).html$ /type.php?typeid={GetProperty(Content)}&page=$2 [PT]
培训新闻
- 绝对高端,开沅教育(大连)中心2009年首期P...
- 开沅教育(大连)中心--09年3月北京交通大学...
- .广州多迪php培训,年前最后一期优惠,大家快...
- 上海实战精英班二期开始报名了~~~~~
- 大连开沅教育09年LAMP首期“就业班”开始报名...
- 北京十一期实战精英班,正在热招中,速速报名...
- 大连开沅教育08年寒假lamp精品培训招生开始,...
- 北京PCTI-19期,正在热招中,年前报名有优惠...
热点专题
网站特别推荐
- 唐山培训中心“首期实战班”赠送联想双核笔记...
- LAMP兄弟连09年课程表
- 绝对高端,开沅教育(大连)中心2009年首期P...
- 2008.12.24李明老师"互联网时代的就业与...
- 上海实战精英班二期开始报名了~~~~~
- 开沅教育(大连)中心--09年3月北京交通大学...
- 北京十一期实战精英班,正在热招中,速速报名...
- 大连开沅教育09年LAMP首期“就业直通车”开始...
- 北京PCTI-19期,正在热招中,年前报名有优惠...
- 12月24日唐山培训中心特邀PHPChina技术总监 ...
社区精华
- linuxroot吐血推荐花了一天时间写的强壮捕获各...
- PHPChina伯乐PHP程序员(1年)
- PHPChina伯乐北京高级的PHP程序员
- PHPChina伯乐浙江 高薪职位!
- PHPChina伯乐网站技术





