加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 使用相对链接从https(或反之亦然)链接到http的简短方式

发布时间:2020-12-14 21:50:00 所属栏目:资源 来源:网络整理
导读:当我在一个网站的安全部分,我正在开发(使用https输入特定的页面或文件夹)时,与正常页面的相关链接也会自动转换为https。 有没有办法告诉 a标签总是使用http协议而不是https协议(或者其他方式)? 我知道使用完整的链接(http://www.mysite.com/index.html或h
当我在一个网站的安全部分,我正在开发(使用https输入特定的页面或文件夹)时,与正常页面的相关链接也会自动转换为https。

有没有办法告诉< a>标签总是使用http协议而不是https协议(或者其他方式)?

我知道使用完整的链接(http://www.mysite.com/index.html或https://www.mysite.com/index.html)很容易,但我希望它可以使用相关链接(index.html,../index.html等)。

解决方法

我们使用Apache mod_rewrite控制是否通过http或https提供了一个页面。以下是站点根目录.htaccess文件的示例代码段:
# Redirect most reqests for https to http
RewriteRule ^https://www.example.com(.*) http://www.example.com$1 [R=301,NC]

# Allow some URIs to be https if requested
RewriteCond   %{SERVER_PORT}  ^443$
RewriteCond   %{REQUEST_URI}  !^/images/(.*)$
RewriteCond   %{REQUEST_URI}  !^/scripts/(.*)$
RewriteCond   %{REQUEST_URI}  !^/styles/(.*)$
RewriteCond   %{REQUEST_URI}  !^/store(.*)$
RewriteCond   %{REQUEST_URI}  !^/login.htm$
RewriteRule ^(.*) http://www.example.com/$1 [L,R]

# Force some URIs to be https only
RewriteCond   %{SERVER_PORT}  ^80$
RewriteRule ^store(.*) https://www.example.com/store$1 [L,R]

RewriteCond   %{SERVER_PORT}  ^80$
RewriteRule ^FormSanityKey.htm https://www.example.com/login$1 [L,R]

阅读全文:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读