【问题标题】:Using htaccess to redirect http to https for Wordpress?使用 htaccess 将 http 重定向到 Wordpress 的 https?
【发布时间】:2014-03-30 05:14:09
【问题描述】:

我已使用以下代码正确启用 HTTPS 重定向。 访问其中一个 HTTPS 页面后,所有其他 url 都继承了以前的 HTTPS。如何强制所有其他页面使用 HTTP?

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/checkout|/downloads|/all-products)
RewriteRule ^(.*)$ https://websitename.com/$1 [R,L]

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite redirect https


    【解决方案1】:

    你可以使用:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^/(checkout|downloads|all-products)
    RewriteRule ^(.*)$ https://websitename.com/$1 [R=301,L,NE]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^/(checkout|downloads|all-products)
    RewriteRule ^(.*)$ http://websitename.com/$1 [R=301,L,NE]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    【讨论】:

    • 谢谢!但是,我正在重定向到 websitename.com/index.php。是不是我的组织不正确?
    • 对于哪个 URL,您被重定向到 websitename.com/index.php
    • 每一个 /(checkout|downloads|all-products) 由于某种原因重定向到索引。
    • 如果你有完全相同的方式,那不是来自这段代码。您能否打开 firebug,然后尝试加载该 URL 以查看您是否有机会获得 2 个重定向。
    • 好的,我会做更多的挖掘工作。非常感谢您的帮助!
    猜你喜欢
    • 2019-04-11
    • 2019-03-18
    • 2012-10-11
    • 2015-11-10
    • 2018-08-31
    • 2015-10-27
    • 2012-11-02
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多