.htaccess 301 将所有 https 重定向到 http,除了一页

编程入门 行业动态 更新时间:2024-10-28 01:15:12
本文介绍了.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 [NC] RewriteRule ^(.*)$ www.example/$1 [L,R=301] RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) %{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:

  • 将example"的所有实例重定向到www.example"
  • 将https//www.example"的所有实例重定向到www.example"除了1 页!!!(以防万一,该页面的文件名是 Payments.php)
  • redirect all instances of "example" to "www.example"
  • redirect all instances of "https//www.example" to "www.example" 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 RewriteEngine On RewriteBase / # Redirect from example to www.example RewriteCond %{HTTP_HOST} ^example [NC] RewriteRule ^(.*)$ www.%{HTTP_HOST}/$1 [R=301,L] # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} /payments.php [NC] RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] # Turn SSL off everything but payments RewriteCond %{HTTPS} on RewriteCond %{SCRIPT_FILENAME} !/payments.php [NC] RewriteRule ^(.*)$ %{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) www.asdf/payments.php - YES (www.asdf) 2) www.asdf/phpinfo.php - NO 3) asdf/phpinfo.php - YES (asdf) 4) www.asdf/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,除了一页

    本文发布于:2023-10-31 17:13:25,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1546745.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重定向   htaccess   http   https

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!