【问题标题】:https htaccess exclude some urlhttps htaccess 排除一些 url
【发布时间】:2014-09-06 02:26:05
【问题描述】:

我知道这个问题被问了很多,但我尝试了很多答案并没有成功。 我尝试这些答案: .htaccess ssl & non-ssl redirects

Remove SSL integration from a specific folder using htaccess

还有一些我在谷歌上找到的。 我在网站的 3 个页面上只有 ssl,我想制定一个一般规则,即其他页面在 https 上时应重定向到 http。我喜欢 Jon Snow 我对 apache 和 htaccess 一无所知。

这就是我目前所尝试的:

RewriteCond %{HTTPS} on
RewriteCond  %{REQUEST_URI} !^\/(page1|page2|page3)+ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]

还有这个:

RewriteCond %{HTTPS} on
RewriteCond  %{REQUEST_URI} !^/page1/$
RewriteCond %{REQUEST_URI} !^/page2/$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]

发送到 http 的部分有效,但异常不发送或全部发送到 http 或重定向到索引。

澄清我没有同时输入两个代码。

其他规则:

RewriteCond %{HTTP_HOST} !^www\.example\.com\$
RewriteRule (.*) http://www.example.com.br/$1 [R=301,L]


RewriteRule !\.(js|txt|ico|gif|GIF|jpg|JPG|png|PNG|css|swf|pdf|xml|XML|eot|EOT|ttf|TTF|woff|WOFF)$ index.php

请求的完整网址: https://www.example.com.br/area-restrita/ 在“area-restrita”部分之后可以有更多信息

【问题讨论】:

  • 提供一个您想要排除但不适合您的完整 URL 示例?你在这个.htaccess中还有其他规则吗?
  • 我编辑问题以放置其他规则
  • 但是您没有提供要排除的完整 URL 示例,并且不适合您
  • 再次编辑,使用完整的网址

标签: apache .htaccess mod-rewrite ssl


【解决方案1】:

试试这个代码:

RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/(area-restrita|page2) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]

RewriteCond %{HTTP_HOST} !^www\.example\.com\$
RewriteRule (.*) http://www.example.com.br/$1 [R=301,L,NE]

RewriteRule !\.(js|txt|ico|gif|GIF|jpg|JPG|png|PNG|css|swf|pdf|xml|XML|eot|EOT|ttf|TTF|woff|WOFF)$ index.php [L,NC]

【讨论】:

  • 它仍然会重定向到所有页面上的 http,即使是“area-restrita”
  • 打开 Firebug 并访问 https://www.example.com.br/area-restrita/。在“网络”选项卡中检查你得到了什么。
  • 我使用 chrome 控制台的网络部分:它给出:302 在 https 和更高版本上找到:200 OK example.com.br/area-restrita 重定向
  • 但我的想法是不要重定向这 2 个页面,我不知道如果没有解释正确,因为英语不是我的第一语言。我想重定向除那些 2 之外的每个 URL。
  • 不客气,很高兴它成功了。由于 zend 框架,这真的很棘手。
【解决方案2】:

如果您想将整个网站重定向到 https,但某些特定目录/URL 除外,并且在这些特殊情况下您仍希望通过 http 提供它们,您可以使用virtual.conf 中的这种技术;否则当 RewriteCond 匹配时,特定页面将始终收到错误 “404 page not found”

<VirtualHost *:80> 
  ServerName www.example.com

  RewriteEngine On 
  RewriteCond %{HTTPS} !=on 
  RewriteCond %{REQUEST_URI} !^/app1/.*$ [NC]
  RewriteCond %{REQUEST_URI} !^/app2/.*$ [NC]
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

  RewriteCond %{HTTP_HOST} !=apps.example.com [NC]
  RewriteCond %{REQUEST_URI} ^/app1/.*$ [NC,OR]
  RewriteCond %{REQUEST_URI} ^/app2/.*$ [NC]
  RewriteRule ^.*$ http://apps.example.com%{REQUEST_URI} [R,L,P] 

</VirtualHost>

<VirtualHost *:80> 
  ServerName apps.example.com
  DocumentRoot /home/sites/example.com/public_html
</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2013-04-10
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2012-02-17
    相关资源
    最近更新 更多