.htaccess 301 将所有 https 重定向到 http,除了一页 [英] .htaccess 301 redirect for all https to http EXCEPT ONE PAGE

查看:28
本文介绍了.htaccess 301 将所有 https 重定向到 http,除了一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前在 .htaccess 文件中的代码:

Here is the code I have currently in my .htaccess file:

Options +FollowSymLinks 
RewriteEngine on
RewriteBase / 
RewriteCond %{HTTP_HOST} ^example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我知道 jack 是关于重写的……关于这个主题的所有其他帖子都不符合我的标准,而且我对语言的了解不够,无法尝试破译它.

I know jack about rewrites...and all of the other posts on this subject really don't fit my criteria and I don't know enough about the language to try and decipher it.

基本上我需要的是这个:

Basically what I need is this:

  1. 将example.com"的所有实例重定向到www.example.com"
  2. https//www.example.com"的所有实例重定向到http://www.example.com"除了1 页!!!(以防万一,该页面的文件名是 Payments.php)
  1. redirect all instances of "example.com" to "www.example.com"
  2. redirect all instances of "https//www.example.com" to "http://www.example.com" with the exception of 1 page!!!! (in case it matters, the filename of that page is payments.php)

我上面的代码有效,但是对于我需要成为 https 的 1 个页面,它将 url 重写为 http.那一页必须是 https.

The code I have above works, but for the 1 page that I need to be https, it is rewriting the url to http. That one page has to be https.

谢谢,克里斯

推荐答案

Apache/2.2.6 (Win32) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6

Apache/2.2.6 (Win32) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6

我已经在本地进行了测试,所有用例似乎都可以正常工作.如果您还有其他问题,请随时提问.

I've tested it locally, all use cases seem to work fine. If you have further questions, feel free to ask.

# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /

# Redirect from example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Turn SSL on for payments
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} /payments.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Turn SSL off everything but payments
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !/payments.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

重要提示!当用户从带有 www 的任何 https 页面导航到任何 https 页面时如果没有 www,他会被要求接受您的非 www 域的安全证书.

IMPORTANT! When the user navigates from any https page with www to any https page without www, he's asked to accept security certificate of your non-www domain.

例如(YES = 请求接受证书,NO - 相反):

For example (YES = request to accept the certificate, NO - opposite):

1) https://www.asdf.com/payments.php - YES (www.asdf.com)
2) http://www.asdf.com/phpinfo.php - NO
3) https://asdf.com/phpinfo.php - YES (asdf.com)
4) https://www.asdf.com/phpinfo.php - NO

我尝试在 .htaccess 中重新排序规则,但没有成功.如果有人找到更好的解决方案,我们将不胜感激.

I tried to reorder rules in .htaccess with no success. If anyone finds a better solution, it'll be highly appreciated.

这篇关于.htaccess 301 将所有 https 重定向到 http,除了一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆