Rewrite and Proxy一例
需求:gtod转到https,其他使用http。所有的访问最后都转到192.168.100.116:8090
httpd.conf
RewriteEngine on
RewriteRule ^/gtod/(.*)$ https://192.168.100.116/gtod/$1 [L,R] //把到gtod的请求转到https。flag使用R用于redirect。
RewriteRule ^/(.*)$ http://192.168.100.116:8090/$1 [P] //把其他的请求转到8090,这行和下一行实现的是一样的功能。注意,使用RewriteRule时需要把/后面的也匹配上。使用ProxyPass则不用。
#ProxyPass / http://192.168.100.116:8090/ //注意这里http://192.168.100.116:8090/ 的最后有个/。
ProxyPassReverse / http://192.168.100.116:8090/ //把proxy的请求reverse回来。
ssl.conf
RewriteEngine on
RewriteRule ^/gtod/(.*)$ http://192.168.100.116:8090/gtod/$1 [P] //把gtod转到8090上。这里使用flag P,proxy的意思。
#ProxyPass /gtod http://192.168.100.116:8090/gtod
ProxyPassReverse /gtod http://192.168.100.116:8090/gtod
RewriteRule ^/(.*)$ http://192.168.100.116/$1 [L,R]
如果访问的URL是一个目录,mod_dir会默认在后面加上/
比如访问http://192.168.100.116/gtod 会自动转到http://192.168.100.116/gtod/
Description: Toggle trailing slash redirects on or off
Syntax: DirectorySlash On|Off
Default: DirectorySlash On