通过 Apache 配置 Rewrite 实现网络服务的 co-branding
2010-02-24 00:00:00 来源:WEB开发网如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代码。此时请务必注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 <VirtualHost> 中去,如果加在虚拟主机配置外部将可能无法使用,改好后将 Apache 重启。稍后再解释这段代码的意思
清单 3. 加入配置文件的代码
LoadModule rewrite_module modules/mod_rewrite.so
<IfModule rewrite_module>
RewriteEngine on
RedirectMatch ^(.*)/([^/]*)\.com$ $1/index.jsp?brand=$2
</IfModule>
如果没有加载这个 mod_rewrite 模块,那多半就是 Apache 本身编译的时候就没有编译上 rewrite 模块了,那我们需要手工自己编译一下这个模块。
先找到你的 Apache 最初编译的源代码目录,找到放 mod_rewrite.c 的目录,例如 :/usr/local/src/httpd-2.2.13/modules/mappers, 然后使用 Apache 安装好的 apxs 命令编译即可:
清单 4. 指向源代码目录的代码
/usr/local/apache2/bin/apxs -i -a -c ./mod_rewrite.c
编译的过程如下:
清单 5. 编译过程的代码
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic
-DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread
-I/usr/local/apache2/include -I/usr/local/apache2/include
-I/usr/local/apache2/include -c -o ./mod_rewrite.lo
./mod_rewrite.c && touch ./mod_rewrite.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o ./mod_rewrite.la
-rpath /usr/local/apache2/modules -module -avoid-version
./mod_rewrite.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool'
./mod_rewrite.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool
--mode=install cp ./mod_rewrite.la /usr/local/apache2/modules/
cp ./.libs/mod_rewrite.so /usr/local/apache2/modules/mod_rewrite.so
cp ./.libs/mod_rewrite.lai /usr/local/apache2/modules/mod_rewrite.la
cp ./.libs/mod_rewrite.a /usr/local/apache2/modules/mod_rewrite.a
chmod 644 /usr/local/apache2/modules/mod_rewrite.a
ranlib /usr/local/apache2/modules/mod_rewrite.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_rewrite.so
[activating module `rewrite' in /usr/local/apache2/conf/httpd.conf]
- ››通过远程管理更改ESXi主机root用户密码
- ››apache设置域名绑定 以及绑定不起作用的排查
- ››apache rewrite将指定URL转向指定的几个服务器
- ››通过JS得到当前焦点(鼠标)的坐标
- ››通过Mysql命令行语句来导入、导出数据库文件
- ››配置MySQL出错The service could not be started....
- ››配置apache虚拟主机
- ››通过查看mysql 配置参数、状态来优化你的mysql
- ››apache配置文件httpd.comf部分参数说明
- ››Apache+Mysql+PHP+phpMyAdmin+Mac OS X 10.7 Lion...
- ››通过oracle的sys密码重置其它密码
- ››apache+tomcat负载均衡_项目实例
更多精彩
赞助商链接