【问题标题】:Having one file non-https on https site and how to write the code in the htaccess file在 https 站点上拥有一个非 https 文件以及如何在 htaccess 文件中编写代码
【发布时间】:2016-06-08 06:40:41
【问题描述】:

我们的软件使用我们网站上的文件来检查它是否有效并被硬编码到软件中,我希望我们的网站转到 https,但希望该文件的目录保留为 http。

【问题讨论】:

  • 请详细说明你的问题,我真的不明白你想要什么。
  • 我希望我的整个站点都是examplesite.com,但是有一个目录examplesite.com/file.txt 可以在不重定向到站点的https 版本的情况下访问。
  • 你的答案对你想要的有用吗?

标签: .htaccess https url-rewriting


【解决方案1】:

您可以使用以下配置将 .htaccess 添加到您的网站根目录:

# This will enable the Rewrite capabilities
RewriteEngine On

# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on

# This checks file name is not file.txt
RewriteCond %{REQUEST_FILENAME} !file.txt

# This redirects to all requests to https 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

请查看reference 了解更多信息。

【讨论】:

  • 我必须使用文件的完整扩展名吗?我无法测试,因为它会立即断开与软件的链接并且人们无法登录。例如,它是 www.siteexample.com/services/files/file.txt 我必须输入 !/services/文件/file.txt 或只是 !file.txt。感谢您的帮助。
  • 不,你不需要,实际上上面检查请求文件名是否包含file.txt,所以它适用于www.siteexample.com/services/files/file.txt,适用于www.siteexample.com/services/file.txt和@987654326 @
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 2021-05-12
  • 2015-11-28
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
  • 2021-04-08
相关资源
最近更新 更多