【发布时间】:2012-02-15 15:47:12
【问题描述】:
问题基于问题htaccess rewriterule: redirect http to https or https to http (both ways) depending on URL typed。很棒的解决方案(感谢 Ulrich Palha)如下所示:
RewriteEngine on
RewriteBase /
#determine if page is supposed to be http
#if it has p=home or p=home1 or qqq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(p=home1?|qqq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]
#all pages that are supposed to be http redirected if https
RewriteCond %{HTTPS} on
RewriteCond %{ENV:IS_HTTP} 1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
#all other pages are sent to https if not already so
RewriteCond %{HTTPS} off
RewriteCond %{ENV:IS_HTTP} !1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
不幸的是,一旦我将此代码添加到 .htaccess 文件中,一切正常,但 https 开始看起来已损坏,如果包含指向 css 或来自服务器的图片的链接,尽管路径是相对的。
以下页面 (https://www.example.com/?p=welcome) 显示 SSL 连接断开,FF 浏览器显示“您与此站点的连接仅部分加密”
<head>
<title>ddd</title>
</head>
<body>
Hello
<img src="/gfx/stars/help.gif" alt="" />
</body>
</html>
为什么?
一旦我从页面中删除<img src="/gfx/stars/help.gif" alt="" />,FF 显示 https 正常,然后 URL 栏为绿色(显示 SSL 证书)。当我使用 Google Chrome 进行测试时,出现了同样的错误。
那么,<img src="/gfx/stars/help.gif" alt="" /> 有什么问题?路径是相对的。
如果我添加也会发生同样的情况
<link rel="stylesheet" type="text/css" href="/css/mycss.css" />
【问题讨论】:
标签: .htaccess mod-rewrite https path relative-path