【问题标题】:.htaccess to redirect http to https for sensitive areas.htaccess 将敏感区域的 http 重定向到 https
【发布时间】:2014-02-09 00:07:52
【问题描述】:

我终于将我的网站从 Joomla 1.5 和 Virtuemart 1.1.9 更新到 Joomla 2.5 和 Virtuemart 2。我尝试为 Virtuemart 中的敏感区域启用 SSL,但它不起作用,我想使用 .htaccess 来访问改为进行重定向。

我已经尝试过这段代码,如果我的网站位于网站的根目录中,但它位于子文件夹中,即 www.uniqbuy.com/electronics,它会起作用

如何让此代码在重定向到 https 时不从 URL 中删除电子设备?

# Force SSL on checkout login account and admin pages
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} checkout|login|my-account|administrator|webshop
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ https://%2/$1 [R=301,L,QSA]

# Remove SSL on other pages
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !checkout|login|my-account|administrator|webshop
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%2/$1 [R=301,L,QSA]

# Force www for non https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA]

任何帮助都会很棒。

谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect ssl


    【解决方案1】:

    您的第二条规则似乎使用了错误的正则表达式。试试这个代码:

    # Force SSL on checkout login account and admin pages
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} (checkout|login|my-account|administrator|webshop)
    RewriteCond %{HTTP_HOST} ^(www\.)?(.+)$ [NC]
    RewriteRule ^(.*)$ https://%2/$1 [R=301,L]
    
    # Remove SSL on other pages
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !(checkout|login|my-account|administrator|webshop)
    RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.%2/$1 [R=301,L]
    
    # Force www for non https
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
    

    【讨论】:

    • 谢谢。我设法让它与我在子文件夹上的安装一起工作,但它没有将购物车内容保留在内存中,在 http 和 https 之间切换。然后发现 Yireo SSL Redirection 很好,解决了所有问题。
    猜你喜欢
    • 2017-04-11
    • 2015-05-19
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    相关资源
    最近更新 更多