使用get参数重定向到https url

时间:2017-04-05 00:08:57

标签: apache .htaccess redirect mod-rewrite

我有.htaccess文件和代码只在woocommerce商店的页面上提供https并且工作完美。那么如何添加允许页面上的https使用GET参数'yandex_money = check'的规则,例如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]

1 个答案:

答案 0 :(得分:0)

所以解决方案是

  • 使用[OR]
  • 添加关于%{REQUEST_URI}的RewriteCond
  • 用RewriteRule [N]和RewriteRule [L]替换RewriteRule [L]。
  • [N]键允许检查Next RewriteRule
  • [L] last是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}