php集成 rewrite_mod 和虚拟主机设置

Some parameters should be modified in the following file  ? include_php/parametres.php ?
line 25 : $mysql_db = "subpro"; // the mysql database name
line 27 : $mysql_hostname = "localhost"; // host for database server
line 28 : $mysql_login = "subpro"; // login
line 29 : $mysql_password = '***********************'; // the password
line 35 : $base = "<base href=\"http://www.subpro.com/\" >"; // the base html tag used in subpro's site.

$mysql_db_stat are not used in chinese version.
==============================================================
如果你的服务器apache还没有安装,那很简单,在编译apache时将 mod_rewrite模块编译进去就可以,相关文档可以在http://man.chinaunix.net/newsoft … ew/mod/mod_rewrite. html中找到。如果你的apache已经安装好了,现在只想编译出mod_rewrite.so模块,在apache中进行加载,下面我们就介绍这个方 法。


以Fedora操作系统进行举例:


1)首次安装apache,在编译时增加–enable-rewrite选项。


如./configure –prefix=/opt/apache –enable-so –enable-mods-shared=all –enable-rewrite –enable-cache


2)增加mod_rewrite模块


# find . -name mod_rewrite.c //在apache的源码安装目录中寻找mod_rewrite.c文件

(2.2.8在目录httpd-2.2.8/modules/mappers下,我找了半天才找到的)

# cd PATH/to/mod_rewrite.c //进入包含mod_rewrite.c文件的目录

# /opt/apache/bin/apxs -c mod_rewrite.c //apxs应指定绝对路径,在你当前正在使用apache的bin目录里

# /opt/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.la


如果没有什么错误的话,应该在你的apache的modules目录中编译出一个mod_rewrite.so文件。


编辑httpd.conf文件,确认httpd.conf中已经包含mod_rewrite.so的加载语句,如下:


LoadModule rewrite_module modules/mod_rewrite.so

检查:

[root@www httpd-2.2.8]# ../bin/apachectl configtest
Syntax OK

这时,你的apache应该已经支持rewrite了。


vicos注:完成之后,记得重启服务器apache。


注意下一步,配置虚拟主机的时候要类似如下设置才可以生效:

<VirtualHost *:80>
DocumentRoot /var/www/www/www.fastu.cn/
ServerName www.fastu.cn
<Directory /var/www/www/www.fastu.cn/>
Options FollowSymLinks
AllowOverride All
order allow,deny
Allow from all
</Directory>
</VirtualHost>
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
安装环境:rhel es 4
apache:1.3.37(源码自己编译安装)
gdbm:1.8.3

1. Apache安装rewrite模块的时候需要DBM支持,否则无法编译,表现为:

[nemo@web standard]$ ~/apache/bin/apxs -c mod_rewrite.c
gcc -DLINUX=22 -DHAVE_SET_DUMPABLE -DUSE_HSREGEX -fpic -DSHARED_MODULE -I/home/nemo/apache/include  -c mod_rewrite.c
In file included from mod_rewrite.c:51:
mod_rewrite.h:91:18: ndbm.h: No such file or directory
mod_rewrite.c: In function `lookup_map_dbmfile':
mod_rewrite.c:3035: error: `DBM' undeclared (first use in this function)
mod_rewrite.c:3035: error: (Each undeclared identifier is reported only once
mod_rewrite.c:3035: error: for each function it appears in.)
mod_rewrite.c:3035: error: `dbmfp' undeclared (first use in this function)
mod_rewrite.c:3036: error: `datum' undeclared (first use in this function)
mod_rewrite.c:3036: error: syntax error before "dbmkey"
mod_rewrite.c:3044: error: `dbmkey' undeclared (first use in this function)
mod_rewrite.c:3047: error: `dbmval' undeclared (first use in this function)
apxs:Break: Command failed with rc=1
[nemo@web standard]$ rpm -qa |grep gdbn
[nemo@web standard]$ rpm -qa |grep gdbm
gdbm-1.8.0-24
gdbm-devel-1.8.0-24


所以首先要安装一个GDBM :下载地址:ftp://ftp.gnu.org/gnu/gdbm/
GDBM安装步骤: 进入安装目录,

./configure
make
make install
make install-compat #否则无法编译出ndbm.h头文件.

2. 然后进入到apache源码包解压目录apache_1.3.37/src/modules/standard,用Apache bin目录下的apxs命令安装,注意apxs使用绝对路径:

cd /path/to/apache_1.3.37/src/modules/standard/
/usr/local/apache/bin/apxs -c mod_rewrite.c
/usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.so

然后在http.conf配置文件里加上:

LoadModule rewrite_module libexec/mod_rewrite.so

接下来用

/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl start

停止apache,然后用再start,千万注意,在这里不能用restart或者graceful参数来重新启动apache,必须先停止,然后再开始,否则rewrite将不起作用。

如果你跟我一样的不幸,遇到dbm_fetch错误问题,那么请按我的尝试来操作:

执行完/usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.so后,这个命令已经帮我们复制mod_rewrite.so模块到libexec目录下并且修改好了httpd.conf文件,但测试却出现dbm_fetch错误:

[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Cannot load /home/nemo/apache/libexec/mod_rewrite.so into server: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: dbm_fetch

google一下,马上发现一篇文章写有解决方法(本文最后贴出),继续尝试:
到 apache_1.3.37/src/modules/standard 目录,执行一下这个命令:

gcc -shared -o mod_rewrite.so mod_rewrite.o -lgdbm
cp mod_rewrite.so /usr/local/apache/libexec/

重新检查一下:

[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Can't locate API module structure `mod_rewrite_module' in file /home/nemo/apache/libexec/mod_rewrite.so: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: mod_rewrite_module

修改 httpd.conf ,将

LoadModule mod_rewrite_module libexec/mod_rewrite.so
改为
LoadModule mod_rewrite libexec/mod_rewrite.so

检查一下:

[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Can't locate API module structure `mod_rewrite' in file /home/nemo/apache/libexec/mod_rewrite.so: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: mod_rewrite

靠!再改:

LoadModule rewrite_module libexec/mod_rewrite.so

检查:

[root@web conf]# ../bin/apachectl configtest
Syntax OK

NND,总算搞定了!

[root@web conf]# ../bin/apachectl restart  
../bin/apachectl restart: httpd restarted

-------------------------------------
google到的解决方法:

http://www.vttoth.com/rewrite.htm
Technical Notes: Undefined symbol 'dbm_fetch' with the Apache server

I tried to include in my Apache Web server's configuration the mod_rewrite module, but when I restarted the server, I received an error:
Cannot load /usr/local/apache/libexec/mod_rewrite.so into server:
/usr/local/apache/libexec/mod_rewrite.so: undefined symbol: dbm_fetch

The problem, as it turns out, is that mod_rewrite.so is compiled incorrectly. It should be linked with a dbm library but it isn't.

If you have an up-to-date set of Apache source files, you can easily solve this problem by manually rerunning the last compilation step of this module, using the correct options. When you execute make mod_rewrite.so in the appropriate directory, it performs this final step:
gcc -shared -o mod_rewrite.so mod_rewrite.lo

Rerun gcc, this time adding a reference to the GNU gdbm library:
gcc -shared -o mod_rewrite.so mod_rewrite.lo -lgdbm

Next, copy the newly created mod_rewrite.so over to /usr/local/apache/libexec or wherever your Apache module files are located.

In my case, this was all that was needed to solve the problem. Your mileage may vary.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

==============================================================
查看linux版本
1) [root@q1test01 ~]# cat /proc/version

   Linux version 2.6.9-22.ELsmp (bhcompile@crowe.devel.redhat.com) (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1 SMP Mon Sep 19 18:00:54 EDT 2005

  2) [root@q1test01 ~]# uname -a

  Linux q1test01 2.6.9-22.ELsmp #1 SMP Mon Sep 19 18:00:54 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux

  3) [root@q1test01 ~]# uname -r

  2.6.9-22.ELsmp

2.查看linux的版本主要有三种方法:

1) 登录到服务器执行 lsb_release -a ,即可列出所有版本信息,例如:

[root@3.5.5Biz-46 ~]# lsb_release -a
LSB Version: 1.3
Distributor ID: RedHatEnterpriseAS
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 1)
Release: 4
Codename: NahantUpdate1
[root@3.5.5Biz-46 ~]#

这个命令适用于所有的linux,包括Redhat、SuSE、Debian等发行版。

2) 登录到linux执行cat /etc/redhat-release ,例如如下:
[root@3.5.5Biz-46 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 1)
[root@3.5.5Biz-46 ~]#

这种方式下可以直接看到具体的版本号,比如 AS4 Update 1

3)登录到linux执行rpm -q redhat-release ,例如如下

[root@3.5.5Biz-46 ~]# rpm -q redhat-release
redhat-release-4AS-2.4
[root@3.5.5Biz-46 ~]#

这种方式下可看到一个所谓的release号,比如上边的例子是2.4
这个release号和实际的版本之间存在一定的对应关系,如下:

redhat-release-3AS-1 -> Redhat Enterprise Linux AS 3
redhat-release-3AS-7.4 -> Redhat Enterprise Linux AS 3 Update 4
redhat-release-4AS-2 -> Redhat Enterprise Linux AS 4
redhat-release-4AS-2.4 -> Redhat Enterprise Linux AS 4 Update 1
redhat-release-4AS-3 -> Redhat Enterprise Linux AS 4 Update 2
redhat-release-4AS-4.1 -> Redhat Enterprise Linux AS 4 Update 3
redhat-release-4AS-5.5 -> Redhat Enterprise Linux AS 4 Update 4

注意:第(2)(3)两种方法只对Redhat Linux有效
========================================================================

/apache/httpd/modules/mappers

/apache/httpd/bin/apxs -c mod_rewrite.c
/apache/httpd/bin/apxs -i -a -n mod_rewrite mod_rewrite.la

LoadModule rewrite_module modules/mod_rewrite.so
=========================================================================
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I’ve given five useful examples of URL rewriting using .htacess. If you don’t know something about url rewriting then please check my older post about url rewriting using .htaccess.


Now let’s look at the examples

1)Rewriting product.php?id=12 to product-12.html

It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.

RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

2) Rewriting product.php?id=12 to product/ipod-nano/12.html

SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.

RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

3) Redirecting non www URL to www URL

If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]

4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

5) Redirecting the domain to a new subfolder of inside public_html.

Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.


RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1

Popularity: 88% [?]

=====================================================================================

RewriteEngine On
RewriteBase /
RewriteRule ^(space|network)\-(.+)\.html$ $1.php?Rewrite=$2 [L]
RewriteRule ^(space|network)\.html$ $1.php [L]
RewriteRule ^([0-9]+)$ space.php?uid=$1 [L]
-----
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\.html$ $2.php?lang=$1
.htaccess

RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

 


<Directory "C:/supersoft/www/subpro/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
 Deny from all
 Allow from all
</Directory>

<VirtualHost *:80>
    ServerAdmin dx_andy@163.com
    DirectoryIndex index.html index.htm index.php
    DocumentRoot C:/supersoft/www/subpro/
    ServerName www.test.com
    ErrorLog C:/supersoft/www/subpro/demo1-error_log
    CustomLog C:/supersoft/www/subpro/demo1-access_log common
</VirtualHost>

/apache/prepro/subpro
====================================
<VirtualHost *:80>
DocumentRoot /apache/prepro/subpro/
ServerName www.subpro.com.cn
<Directory /apache/prepro/subpro/>
Options FollowSymLinks
AllowOverride All
order allow,deny
Allow from all
</Directory>
</VirtualHost>

 

<VirtualHost *:80>
DocumentRoot /apache/prepro/
ServerName www.prepro.com.cn
<Directory /apache/prepro/>
Options FollowSymLinks
AllowOverride All
order allow,deny
Allow from all
</Directory>
</VirtualHost>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值