参考
http://helpful.knobs-dials.com/index.php/Apache_config_and_.htaccess_-_URL_rewriting#Server_redirecting.2Fproxying_.28internal.29
http://shiningray.cn/proxypass-directive-in-apache.html
不能再htaccess中设置 proxypass。必须在Context: server config, virtual host, directory
见
http://stackoverflow.com/questions/12808506/can-proxypass-and-proxypassreverse-work-in-htaccess
如果在htaccess中设置,页面会提示500 server error错误。
且会在error.log中报错,提示“proxpass not allow in htaccess”
查看apache 错误日志
tail /var/log/apache2/error.log
因此需要到vhost文件中设置。
添加
ProxyRequests Off
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
ProxyPass /log http://ifeng.com
ProxyPassReverse /log http://ifeng.com
这样,当域名+/log 访问就会显示www.ifeng.com的内容了。
修改了vhost文件必须reload才能生效。
reload apache命令:
sudo /etc/init.d/apache2 reload
在window上试了,但是是直接跳转到ifeng.com。url变了。不知道为什么。同样开启了
proxy,proxy_http的功能。
设置如下
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/wamp/www/it-os-moreversus-cms"
ServerName moreversus-cms-local
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
ProxyRequests Off
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
ProxyPass /log http://ifeng.com
ProxyPassReverse /log http://ifeng.com
</VirtualHost>
也可以不修改vhost,只修改htaccess設置代理。需要給RewriteRule添加[P] proxy的設置。
参考设置
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/abc2014
RewriteRule ^abc2014(.*) http://dev.target.nmg.com.hk/eventId/21$1 [P]
# 返回的url用abc2014重定向。因為無eventId的頁面
RewriteCond %{REQUEST_URI} ^/eventId/21
RewriteRule ^eventId/21(.*) abc2014$1 [R]
RewriteCond %{REQUEST_URI} ^/Public
RewriteRule (.*) http://dev.target.nmg.com.hk/$1 [P]
RewriteCond %{REQUEST_URI} ^/Voting
RewriteRule (.*) http://dev.target.nmg.com.hk/$1 [P]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(!abc2014|!Public|!Voting)(.*) /index.php [L]
</IfModule>
# END WordPress
rewrite flag
http://httpd.apache.org/docs/2.2/rewrite/flags.html