【问题标题】:How to disable SSL if a page url contains a specific word如果页面 url 包含特定单词,如何禁用 SSL
【发布时间】:2016-01-04 06:50:13
【问题描述】:

我的网站在整个 SSL 上运行,但我添加了一个使用 Flash 中的 3rd 方游戏的游戏部分。当我启用 SSL 它停止工作。我想知道我是否只能在 URL 中包含“/game/”的特定页面上禁用 SSL,以便游戏能够正常运行。

我在我的 .htaccess 文件中尝试了来自 insternet 的这段代码,但没有工作:

RewriteCond %{HTTPS} off
RewriteRule ^game^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

编辑:

我尝试了建议的答案:

RewriteEngine On
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

它有效,但是当我转到包含“游戏”一词的页面时,它会将其他页面也变成“http”,并且其他页面使用“http”而不是“https”

然后我尝试了这个:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

当我转到“游戏”页面 url 时,它开始给我消息“页面未正确重定向”。

我只希望“游戏”页面使用“http”。

编辑二:完整的 .htaccess 文件

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On

# @todo This may not be effective in some cases
FileETag Size

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

需要帮助。如果找到任何重复项,请告诉我,但我找不到任何人。 谢谢。

【问题讨论】:

  • 如果您的 .htaccess 帖子中有更多规则,请在此处填写 .htaccess。
  • 我添加了完整的代码。

标签: .htaccess mod-rewrite ssl https url-redirection


【解决方案1】:

这应该是您的完整 .htaccess:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

  # except for /game/ enforce https
  RewriteCond %{HTTPS} off
  RewriteCond %{THE_REQUEST} !/game/ [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # for /game/ enforce http
  RewriteCond %{HTTPS} on
  RewriteCond %{THE_REQUEST} /game/ [NC]
  RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} public [OR]
  RewriteCond %{REQUEST_URI} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

确保在测试此更改之前清除浏览器缓存。

【讨论】:

  • 它给了我相同的 htaccess 文件的错误“ERR_TOO_MANY_REDIRECTS”。
  • 这意味着您在浏览器中仍有旧缓存。在禁用缓存的 Chrome 开发工具中进行测试。然后在Network 选项卡中监视您看到的 301/302 重定向 URL。顺便说一句,/game/ 也有 .htaccess 吗?
  • 我尝试了你的建议,使用禁用缓存选项以及私人浏览我正在使用模块中没有 htaccess 文件的 zend 应用程序,而游戏是一个模块。 root 下只有一个 htaccess 文件。
  • 确定您输入的测试 URL 以及您在禁用缓存的 Chrome 开发工具的 Network 选项卡中看到的 301/302 重定向?
  • 我输入了我的域名,例如 www.example.com,在网络选项卡中,我看到请求转到 https://www.example.com/,状态代码为“302 Moved Temporarily”,经过几次重定向显示相同的 302 状态“此网页有重定向循环 ERR_TOO_MANY_REDIRECTS”
猜你喜欢
  • 1970-01-01
  • 2016-03-23
  • 1970-01-01
  • 2019-07-22
  • 1970-01-01
  • 2019-01-03
  • 2013-07-02
  • 2015-04-01
  • 1970-01-01
相关资源
最近更新 更多