Apache:在HTTPS上运行站点时通过HTTP提供资源
我们的网站运行在HTTPS上。有没有办法接受包含/public/
的URL的HTTP请求?对于所有其他HTTP请求,它们应该重定向到HTTPS。Apache:在HTTPS上运行站点时通过HTTP提供资源
我有RoR
应用程序运行在apache
+ passenger
。
编辑
由于资产(/public/)
请求将被明确地对HTTP
,如何创建另一个VHOST
处理HTTP
请求。并且对于除/public/
之外的任何请求都可以直接重定向到HTTPS
?如果我们可以这样做,我们如何设置VHOST
为HTTP
?
EDIT 2
我很抱歉,我应该已经在首位阐述这一点。这是我们的设置。有两个独立的应用程序一个在HTTPS(S
)上运行,另一个在HTTP上运行(P
)。应用程序P
从S
中提取数据(完整的HTML页面,称为page
)并呈现给客户端。在page
中使用的CSS文件位于'S',所以我需要在CSS链接中使用HTTPS。我想用HTTP来引用CSS。
您可以使用mod_rewrite
并在您的DocumentRoot
中放置一个.htaccess
文件,其中包含以下内容。
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase/
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule^- [L]
Rewritecond %{REQUEST_URI} .*/public/.* [NC]
RewriteCond %{HTTPS} on
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Rewritecond %{REQUEST_URI} !.*/public/.* [NC]
RewriteCond %{HTTPS} off
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
NameVirtualHost *:80
Listen 80
Listen 443
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /pathto/DocumentRoot
ServerName domain.com
ErrorLog path/to/your-error_log
CustomLog path/to/your-access_log common
RewriteEngine on
RewriteBase/
Rewritecond %{REQUEST_URI} !.*/public/.*$ [NC]
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot /pathto/DocumentRoot
ServerName domain.com
ErrorLog path/to/your-error_log
CustomLog path/to/your-access_log common
RewriteEngine on
RewriteBase/
Rewritecond %{REQUEST_URI} .*/public/.*$ [NC]
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#All the other directives pertaining to SSL add below
</VirtualHost>
谢谢,我会试一试,让你知道它是怎么回事。 – Saim 2012-02-15 17:12:05
@ Imran sure .... – ThinkingMonkey 2012-02-15 17:13:58
由于资产('/ public /')请求将显式地在HTTP上,所以如何创建另一个'VHOST'来处理HTTP请求。而对于'/ public /'以外的任何请求可以直接重定向到HTTPS?如果我们可以这样做,那么我们如何在HTTP的'VHOST'中设置它? – Saim 2012-02-16 14:59:32
您的用户可能会得到一个浏览器警告有关混合(安全+不安全)的内容。 – 2012-02-16 15:07:49
请参阅上面我的问题中的编辑2。 – Saim 2012-02-16 16:21:37