+ -
当前位置:首页 → 问答吧 → 记录一下刚用mod_rewrite做的分域名以及静态化链接 codeigniter

记录一下刚用mod_rewrite做的分域名以及静态化链接 codeigniter

时间:2009-02-24

来源:互联网

1.看看你的apache2/bin/httpd -l
里面有没有 mod_rewrite.so
没有的话请重编译 --with-rewrite
2.httpd.conf增加 load module(语法自己查)
重启apache的时候如果出现什么 in build的时候,表示已经把该模块编译到apache了,不需要加载了,去掉刚才那行 httpd.conf
3.打开你的conf/extra/httpd-vhosts.conf
找到你的虚拟主机,这是我的配置文件
我需要把7个频道分出来,注意,主机头正则不能.+?匹配,这样会干掉你的img.domain.com,所以谨慎点好
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/data0/wwwroot/www2.domain.com/"
    ServerName www.domian.com
    ServerAlias game.domain.com soft.domain.com video.domain.com theme.domain.com ebook.domain.com pic.domain.com audio.domain
i.com domain.com
    ErrorLog "|/usr/local/sbin/cronolog /data1/logs/httpd/www2/error_log.%Y%m%d"
    CustomLog "|/usr/local/sbin/cronolog /data1/logs/httpd/www2/access_log.%y%m%d" combined
    RewriteEngine on
    RewriteCond   %{HTTP_HOST}                 ^(game|soft|video|theme|pic|audio|ebook)\.domain\.com$
    RewriteRule   ^(.+)         %{HTTP_HOST}$1          [C]
    RewriteRule   ^(game|soft|video|theme|pic|audio|ebook)\.domain\.com(\/*)$ /index.php/$1
    RewriteRule   ^(game|soft|video|theme|pic|audio|ebook)\.domain\.com\/(lists|detail)\/(.*?)\.html$ /index.php/$1/$2/$3
</VirtualHost>

以上配置,能帮我把 http://www.domain.com/index.php/game 伪装为 http://game.domain.com
http://game.domain.com/lists/2/40.html => http://www.domain.com/index.php/game/lists/2/40
注意apache2/bin/apachectl restart

作者: anvycn   发布时间: 2009-02-24

关键是url 正则匹配。

作者: 逆雪寒   发布时间: 2009-02-24

我觉得那个你不如建个二级域名指向了。
如果要是应用到会员每人一个链接上,这样实验还算可以理解。我觉得这样apache的增加不少负载吧

作者: anyforever   发布时间: 2009-03-03