Chinaunix

标题: 求mod_rewrite规则,教会我rewrite模块者我送500分。 [打印本页]

作者: 3645636    时间: 2008-12-13 18:27
标题: 求mod_rewrite规则,教会我rewrite模块者我送500分。
apache版本:2.2.10
系统:centos 5.2

问题:
  域名www.my.cn,WEB目录为/usr/local/httpd/htdocs
     事先,我已经加入alias /html /var/www/html,,并且访问www.my.cn/html,已经可以访问!
     当用户在浏览器访问http://www.my.cn/时,这个URL将自动跳转至http://www.my.cn/html/

别用HTML实现!


小弟不才,如果哪位高手教会我用Rewrite模块,我单独送给500分,CU为证.
看过正则表达式: 知道.*$^ -i这些元字符的意思 [0-9] [a-z]等!

[ 本帖最后由 3645636 于 2008-12-13 18:32 编辑 ]
作者: ziggler    时间: 2008-12-15 10:10
http://man.chinaunix.net/newsoft ... od/mod_rewrite.html
作者: 75252    时间: 2008-12-16 18:09
HTML不也很舒服么?
作者: 郁闷RMB    时间: 2008-12-17 16:56
RewriteRule  (http://www.my.cn)/$   $1/html/
作者: yanxt    时间: 2008-12-23 14:20
首先load
LoadModule rewrite_module modules/mod_rewrite.so

其次
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog "/usr/local/apache/logs/rewrite.log" #你的LOG文件
RewriteLogLevel 10
RewriteRule ^http://www.my.cn/ "http://www.my.cn/html/"[R,L] #这是就是实现的地方
</IfModule>

可参照二楼的地址
http://man.chinaunix.net/newsoft ... od/mod_rewrite.html
作者: h_xin8211    时间: 2008-12-23 14:35
标题: 回复 #1 3645636 的帖子
参照rewrite模块官方文档如下:

移动过的DocumentRoot

描述:
通常,web服务器的DocumentRoot直接对应于URL"/",但是它常常不是处于最高的一级。比如,你希望访问者在进入网站时首先进入/about/目录。可以使用下面给出的规则集。

解决方案:
只需将"/"重定向到"/about/"即可:
RewriteEngine on
RewriteRule   ^/$  /about/  [R]

也可以使用RedirectMatch指令解决问题:
RedirectMatch ^/$ http://example.com/e/www/

--------------------------------------------------------------------------

你的案例解决如下:
RewriteEngine on
RewriteRule   ^/$  /html/  [R]
作者: hiller1    时间: 2008-12-25 09:39
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2