【问题标题】:redirect to https url with get parameter使用 get 参数重定向到 https url
【发布时间】:2017-04-05 00:08:57
【问题描述】:

我有 .htaccess 文件,代码只在 woocommerce 商店的页面上提供 https 并且运行良好。那么如何使用 GET 参数“yandex_money=check”在页面上添加允许 https 的规则,例如 https://example.com/?yandex_money=check

RewriteEngine On
    # Force HTTPS for /(cart|checkout|my-account|product-category|shop|product)
    RewriteCond %{HTTPS} !=on
    RewriteCond %{THE_REQUEST} ^[A-Z]+\s/(cart|checkout|my-account|product-category|shop|product) [NC]
    RewriteRule ^(cart|checkout|my-account|product-category|shop|product) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

    # Force HTTP for anything which isn't /(cart|checkout|my-account|product-category|shop|product)
    RewriteCond %{HTTPS} =on
    RewriteCond %{THE_REQUEST} !^[A-Z]+\s/(cart|checkout|my-account|product-category|shop|product) [NC]
    RewriteRule !^(cart|checkout|my-account|product-category|shop|product) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    所以解决办法是

    • 使用 [OR] 添加关于 %{REQUEST_URI} 的 RewriteCond
    • 将 RewriteRule [L] 替换为 RewriteRule [N] 和 RewriteRule [L]。
    • [N] 键允许检查 Next RewriteRule
    • [L] 最后是 RewriteRule。

    固定 .htaccess 文件:

    RewriteEngine On
    
    # RewriteCond %{HTTPS} on
    # RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # Force HTTPS for /(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login) GET[yandex_money]
    RewriteCond %{THE_REQUEST} ^[A-Z]+\s/(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login) [OR,NC]
    #RewriteCond %{QUERY_STRING} ^yandex_money=check [NC]
    RewriteCond %{HTTPS} !=on
    
    RewriteRule ^(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login) https://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING}[NC,R=301,N]
    RewriteRule ^(yandex_money) https://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING}[NC,R=301,L]
    
    # Force HTTP for anything which isn't /(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login)
    RewriteCond %{HTTPS} =on
    RewriteCond %{THE_REQUEST} !^[A-Z]+\s/(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login) [NC]
    RewriteCond %{QUERY_STRING} !^yandex_money=check [NC]
    RewriteRule !^(cart|checkout|my-account|product-category|shop|product|wp-admin|wp-login) http://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多