.htaccess - 除少数页面和脚本外的所有 HTTPS 到 HTTP

标签 .htaccess http redirect ssl https

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

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

基本上,站点上的所有页面都需要从 HTTPS 重定向回 HTTP,除了少数 html 页面、一些 .php 页面和一个 .cgi 脚本。你能告诉我是否有一个简单的规则来将所有 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]

最佳答案

Can you tell me if there's an easy rule to set all php pages to be HTTPS, and then set a few additional HTML pages behind HTTPS and a .cgi script?

如果请求不是 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]

关于.htaccess - 除少数页面和脚本外的所有 HTTPS 到 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13024273/

相关文章:

apache - htaccess 规则 (mod_rewrite) 转换为 web.config 规则

java - 如何定义要从生产中的不同子目录提供服务的 Play Assets 和 API?

php - Cakephp 2.x 停放域 https 不工作

linux - 用于查找机器人元标记值的 Bash shell 脚本

apache - 将子域名重定向到相同子域名但不同域名

rest - PATCH 方法是否应该在响应正文中返回资源的所有字段?

ios - 使用 AFNetworking 将图像上传到服务器时已损坏

javascript - 2xx 范围内的 jQuery ajax 自定义 HTTP 状态消息

redirect - 使用 SSL 的 www 重定向的 mod_rewrite

php - .htaccess 使用 SSL 将 www 重定向到非 www