有这么一个实例,需要把APACHE的HTTP成HTTPS,并且产品子站点名太长需要重定向到根站点里。
根据REWRITE机制,这个可以很容易在APACHE配置中实现。
分别在APACHE主配置文件和SSL子配置文件分别配置以下内容
httpd.conf -----
RewriteEngine on
SSLProxyEngine On
RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*)$ [url]https://%[/url]{SERVER_NAME}$1 [L]
SSLProxyEngine On
RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*)$ [url]https://%[/url]{SERVER_NAME}$1 [L]
ssl.conf---------
RewriteEngine on
RewriteRule ^/$ /abcdefghijklmn/index.html [P,L]
RewriteRule ^/([^/]*)$ /abcdefghijklmn/$1 [P,L]
RewriteRule ^/icon/([^/]*)$ /abcdefghijklmn/icon/$1 [P,L]
RewriteRule ^/js/([^/]*)$ /abcdefghijklmn/js/$1 [P,L]
RewriteRule ^/css/([^/]*)$ /abcdefghijklmn/css/$1 [P,L]
RewriteEngine on
RewriteRule ^/$ /abcdefghijklmn/index.html [P,L]
RewriteRule ^/([^/]*)$ /abcdefghijklmn/$1 [P,L]
RewriteRule ^/icon/([^/]*)$ /abcdefghijklmn/icon/$1 [P,L]
RewriteRule ^/js/([^/]*)$ /abcdefghijklmn/js/$1 [P,L]
RewriteRule ^/css/([^/]*)$ /abcdefghijklmn/css/$1 [P,L]
虽然容易,其中的两个细节还是需要提醒朋友们注意:第一个在主配置文件中,RULE FLAG不能带P,而SSL配置中必须带P。P表示Proxy。
本文转自 dannyy1026 51CTO博客,原文链接:
http://blog.51cto.com/dannyyuan/40278