【问题标题】:HTTPS to HTTP for all but a few pages and scriptsHTTPS 到 HTTP 用于除少数页面和脚本之外的所有页面
【发布时间】:2012-10-13 00:30:00
【问题描述】:

我正在尝试帮助一位朋友,她的客户在一次黑客攻击后将她的整个网站下意识地引入了 SSL。这对她的 SEO 造成了严重破坏,导致重复页面被编入索引,导致旧链接不再指向正确 URL 的 PageRank 流失,等等。

无论如何,我在 another post on here 之后建模了 .htaccess,这似乎几乎符合要求,但我想由这里的专家运行它以确保文件看起来正确。

基本上,除了少数 html 页面、一些 .php 页面和 .cgi 脚本之外,站点上的所有页面都需要从 HTTPS 重定向回 HTTP。你能告诉我是否有一个简单的规则将所有 php 页面设置为 HTTPS,然后在 HTTPS 和 .cgi 脚本后面设置一些额外的 HTML 页面?我真的很感激。到目前为止,这是我所得到的:

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit GET POST>
order deny,allow
deny from all
</Limit>
AuthName thedomain.com
AuthUserFile /home/thesitename/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/thesitename/public_html/_vti_pvt/service.grp

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} page1.html
RewriteCond %{REQUEST_URI} page2.html
RewriteCond %{REQUEST_URI} page3.html
RewriteCond %{REQUEST_URI} page4.html
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC]
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(auth|register|secure)
RewriteCond %{REQUEST_URI} !originalpage.php
RewriteCond %{REQUEST_URI} !cgi-script.cgi
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]

【问题讨论】:

    标签: .htaccess http redirect ssl https


    【解决方案1】:

    你能告诉我是否有一个简单的规则将所有 php 页面设置为 HTTPS,然后在 HTTPS 和 .cgi 脚本后面设置一些额外的 HTML 页面?

    如果请求不是 HTTPS

    ,此规则会将所有 php 脚本、4 个 html 页面和一个 cgi 脚本重定向到 HTTPS
    RewriteCond %{HTTPS} off
    RewriteCond ${REQUEST_URI} \.php$ [OR]
    RewriteCond %{REQUEST_URI} /page1.html$ [OR]
    RewriteCond %{REQUEST_URI} /page2.html$ [OR]
    RewriteCond %{REQUEST_URI} /page3.html$ [OR]
    RewriteCond %{REQUEST_URI} /page4.html$ [OR]
    RewriteCond %{REQUEST_URI} /cgi-script.cgi$ 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    此规则正好相反,将任何 HTTPS 而非 php 脚本、这 4 个 html 页面或 cgi 脚本重定向到 HTTP

    RewriteCond %{HTTPS} on
    RewriteCond ${REQUEST_URI} !\.php$
    RewriteCond %{REQUEST_URI} !/page1.html$
    RewriteCond %{REQUEST_URI} !/page2.html$
    RewriteCond %{REQUEST_URI} !/page3.html$
    RewriteCond %{REQUEST_URI} !/page4.html$
    RewriteCond %{REQUEST_URI} !/cgi-script.cgi$ 
    RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    【讨论】:

    • 嘿!谢谢!对此,我真的非常感激!对于迟到的回复,我非常非常抱歉;我从来没有收到一封电子邮件说线程已更新,并且忘记了它。我会尝试这个建议并回复结果。再次感谢您的宝贵时间和帮助!
    • 你,先生,(没有不尊重他的光泽)是来自火星的摇滚明星!它完美地工作!再次感谢!你是一个救生员。我还有一个与此相关的问题。我已经删除了一堆不再相关的页面(其中大部分可以追溯到 1997 年并且有大量断开的链接)但为了保留 PageRank,我想将它们 301 转到相关页面或主页(如果没有找到相关页面)。我在您提供的最后一行之前删除了 301,但出现 500 服务器错误。我究竟做错了什么?格式:重定向301 /a-page.html site-home-page.com
    猜你喜欢
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多