【问题标题】:Force HTTP Except Specific Pages in htaccess (SEO)强制 HTTP 除了 htaccess (SEO) 中的特定页面
【发布时间】:2013-10-16 05:51:49
【问题描述】:

我正在尝试对电子商务网站进行搜索引擎优化。该网站在 Wordpress 平台上使用 WooCommerce 插件。此外,它还有一个 authorize.net 网关,允许用户直接在现场付款。这意味着该站点需要 SSL 证书。

出于 SEO 的原因,我希望/需要网站在 HTTP 协议上运行,但支付网关页面(/cart、/my-account、/checkout 等)除外,它应该指向HTTPS 协议。

目前我有以下代码:

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/cart/
RewriteCond %{REQUEST_URI} !^/checkout/

RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

使用此代码,我遇到了一些问题。首先是当我访问“购物车”页面时,它不会重定向到 https,但结帐页面会。

其次,当结帐页面确实加载时,它不会加载我的一些托管内容(Css、JS、img 等...)。我猜这是因为它们没有在相同的 https 协议上运行。我该如何解决?

第三,当我使用https://mydomain.com/somepage手动访问网站时,并不是301重定向到http://mydomain.com/somepage版本。

所有这些都让我相信我上面的代码没有正确编写。有人有什么想法吗? SEO 很重要,因此唯一应该显示的页面是 http:// 页面(我指定的页面除外)。 https 版本被 301 重定向到 http://

这是我的 htaccess 文件现在的样子 -

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

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/cart/
RewriteCond %{REQUEST_URI} !^/checkout/

RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

<FilesMatch "^(wp-comments-post\.php)">
Order Allow,Deny
Deny from xx.xxx.xx.
Deny from xx.xxx.xx.
Deny from xx.xxx.xx.
Allow from all
</FilesMatch>

【问题讨论】:

    标签: wordpress apache .htaccess https seo


    【解决方案1】:

    将 SSL/非 SSL 重定向放在您的 wordpress 规则之前。您还需要规则不仅将 重定向到 HTTPS,而且将 HTTPS 重定向到 HTTP:

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

    【讨论】:

    • 如何为 HTTPS 关闭条件添加更多 RewriteRule?比如“我的账户”页面?我会继续喜欢 - (cart|checkout|my-account|etc...)/ https://...?
    • @AndrewGlover 是的,但还要确保在 HTTP 重定向中添加 RewriteCond %{REQUEST_URI} !^/my-account/ 行,否则您可能会创建一个循环
    猜你喜欢
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 2019-10-01
    • 1970-01-01
    相关资源
    最近更新 更多