Chinaunix

标题: rewrite 重写内容而URL地址不变问题请教? [打印本页]

作者: superhoo    时间: 2007-03-27 12:46
标题: rewrite 重写内容而URL地址不变问题请教?
我的配置文件如下:
<VirtualHost *>
    RewriteLog       logs/rewrite.log
    RewriteLogLevel  3
    RewriteEngine    On
   RewriteCond %{HTTP_HOST} ^[a-z0-9]+\.pinkers\.com\.cn$
   RewriteRule ^/(.*)$ /%{SERVER_NAME}/$1
   RewriteRule  ^/www\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn/show/stati
cpage/company/index.html
   RewriteRule ^/(.*[a-zA-Z]+.*)\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn
/webhome/home/$1/index.html
   RewriteRule  ^/([0-9]+)\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn/show/
staticpage/company/infolist/$1\.html
</VirtualHost>

如果按照这样的配置,URL重新定向是没有问题的。

但是如果我加上反向代理参数[P],则不能实现反向代理,不知道为什么,请指教

<VirtualHost *>
    RewriteLog       logs/rewrite.log
    RewriteLogLevel  3
    RewriteEngine    On
   RewriteCond %{HTTP_HOST} ^[a-z0-9]+\.pinkers\.com\.cn$
   RewriteRule ^/(.*)$ /%{SERVER_NAME}/$1
   RewriteRule  ^/www\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn/show/stati
cpage/company/index.html  [P]
   RewriteRule ^/(.*[a-zA-Z]+.*)\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn
/webhome/home/$1/index.html  [P]
   RewriteRule  ^/([0-9]+)\.pinkers\.com\.cn/?$  http://www.pinkers.com.cn/show/
staticpage/company/infolist/$1\.html [P]
</VirtualHost>
作者: superhoo    时间: 2007-03-27 17:33
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (2) init rewrite engine with requested uri /
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (3) applying pattern '^/?$' to uri '/'
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (2) rewrite / -> /www.pinkers.com.cn/
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (3) applying pattern '^/www\.pinkers\.com\.cn/?$' to uri '/www.p
inkers.com.cn/'
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (2) rewrite /www.pinkers.com.cn/ -> http://www.pinkers.com.cn/sh
ow/staticpage/company/index.html
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (2) forcing proxy-throughput with http://www.pinkers.com.cn/show
/staticpage/company/index.html
2.2.2.2 - - [27/Mar/2007:17:25:10 +0800] [www.pinkers.com.cn/sid#80e8b30][rid#e6
b02538/initial] (1) go-ahead with proxy request proxy:http://www.pinkers.com.cn/
show/staticpage/company/index.html [OK]
日志信息如上,好像已经rewrite了,但是就是不redirect
作者: HonestQiao    时间: 2007-03-27 17:38
1. 停止apache
2. 清空rewrite和error log
3. 启动apache
4. 测试
5. 访问结果是什么?
6. 日志帖上来。
作者: ghbspecial    时间: 2007-03-27 19:46
因为你没配置apache支持mod_proxy这个模块.
cd apache2.0
./configure --enable-MODULE=shared --enable-so --with-mpm=worker --enable-rewrite=shared --enable-proxy=shared
make && make install

之后添加下面内容这个四行内容到http.conf中。
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
作者: superhoo    时间: 2007-03-27 20:07
我访问www.pinkers.com.cn,提示DNS错误
我的error_log
[Tue Mar 27 20:02:02 2007] [error] [client 202.96.179.188] proxy: DNS lookup fai
lure for: www.pinkers.com.cn returned by /

我的rewrite_log
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (2) init rewrite engine with requested uri /
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (3) applying pattern '^/?$' to uri '/'
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (2) rewrite / -> /www.pinkers.com.cn/
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (3) applying pattern '^/www\.pinkers\.com\.cn/?$' to uri '
/www.pinkers.com.cn/'
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (2) rewrite /www.pinkers.com.cn/ -> http://www.pinkers.com
.cn/show/staticpage/company/index.html
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (2) forcing proxy-throughput with http://www.pinkers.com.c
n/show/staticpage/company/index.html
202.96.179.188 - - [27/Mar/2007:20:02:02 +0800] [www.pinkers.com.cn/sid#80e8b30]
[rid#8253ae8/initial] (1) go-ahead with proxy request proxy:http://www.pinkers.c
om.cn/show/staticpage/company/index.html [OK]
作者: superhoo    时间: 2007-03-27 20:10
我的http.conf里面有loadmodule 相关proxy模块的语句啊,我已经打开了
而且我以前配置的http://IP地址/ddd,是能够实现地址跳转,而且显示的url不变的
配置文件如下:
NameVirtualHost *
<VirtualHost *>
    RewriteLog       logs/rewrite.log
    RewriteLogLevel  3
    RewriteEngine    On
    RewriteCond %{HTTP_HOST}   ^128\.129\.97\.135/(.*[a-zA-Z0-9]+.*)\/$
   RewriteRule ^/.*\/$  http://%{SERVER_NAME}/$1
   RewriteRule ^/www\/$ http://%{SERVER_NAME}
   RewriteRule ^/(.*[a-zA-Z]+.*)\/$  http://%{SERVER_NAME}/webhome/home/$1/index
.html [P]
   RewriteRule  ^/([0-9]+)\/$  http://%{SERVER_NAME}/show/staticpage/company/inf
olist/$1\.html [P]
</VirtualHost>
作者: superhoo    时间: 2007-03-27 21:50
如果这台apache服务器做proxy,这台服务器是不是要配置DNS,并且能够访问公网呢?
目前这台服务器我只让公网访问它,没有把它访问公网,DNS,放开




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