【问题标题】:htaccess force ssl except for rss feedshtaccess 强制 ssl,RSS 提要除外
【发布时间】:2013-01-15 01:42:33
【问题描述】:

我的网站目前在所有地方都强制使用 SSL。这是我想要的方式,只是它会导致我的 RSS 驱动的时事通讯和 feedburner 出现问题。因此,我需要对我的提要进行例外处理。

有人可以帮助制定正确的 htaccess 规则来解决这个问题吗?

我的供稿是

/feed
/shop/feed
/forum/discussions/feed.rss

这是我强制 SSL 的条件。除了强制所有 RSS 提要之外,此方法有效。

# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/forum [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]

我尝试了以下方法,但似乎无法正常工作。

# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/forum [OR]
RewriteCond %{REQUEST_URI} !^/feed [OR]
RewriteCond %{REQUEST_URI} !^/shop/forum [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]

非常感谢您的帮助!


更新:这是我当前位于服务器根目录中的 .htaccess 文件。这目前正在将http://photoboothowners.com/feed 重定向到https://photoboothowners.com(注意它正在删除提要目录)。

RewriteEngine on


# Use PHP5CGI as default
AddHandler fcgid-script .php

RewriteCond %{HTTP_HOST} ^buyaphotobooth\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.buyaphotobooth\.net$
RewriteRule ^/?$ "https\:\/\/photoboothowners\.com\/starting\-a\-photo\-booth\-business\-build\-or\-buy" [R=301,L]

RewriteCond %{HTTP_HOST} ^photoboothforums\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.photoboothforums\.com$
RewriteRule ^/?$ "https\:\/\/photoboothowners\.com\/forum" [R=301,L]

# Force SSL
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/forum [NC]
RewriteCond %{REQUEST_URI} !feed   [NC]
RewriteRule ^/?(.*)$ https://photoboothowners.com/$1 [R=301,QSA,L,NE]


RewriteCond %{HTTP_HOST} ^photoboothowners\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.photoboothowners\.com$
RewriteRule ^how\-to\-use\-our\-premium\-print\-designs\-in\-breeze\-dslr\-remote\-pro\/?(.*)$ "https\:\/\/photoboothowners\.com\/how\-to\-use\-our\-photo\-booth\-template\-designs\-in\-breeze\-dslr\-remote\-pro$1" [R=301,L]

RewriteOptions inherit

# 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 %{HTTP_HOST} ^.*$
RewriteRule ^shop\/photo\-booth\-layouts\-and\-samples\.html$ "https\:\/\/photoboothowners\.com\/shop" [R=301,L]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

【问题讨论】:

    标签: wordpress apache .htaccess rss


    【解决方案1】:

    您的规则使用OR,因此它们读作:

    if server port is 80 and the request is not forum OR it is not feed OR it is not shop/forum

    这将匹配所有内容。去掉这两个 [OR] 以便匹配显示:

    if server port is 80 and the request is not forum AND it is not feed AND it is not shop/forum

    编辑:

    根据您更新的问题,以下行缺少斜杠:

    RewriteCond %{REQUEST_URI} !feed [NC]

    应该是

    RewriteCond %{REQUEST_URI} !/feed [NC]

    【讨论】:

    • 谢谢我已经这样做了。我将完整的 .htaccess 文件附加到我原来的问题中。
    • 遗憾的是没有变化。我确实尝试添加以下内容。这导致了一个无限循环,告诉我我错过了一些强制 SSL 的东西。我现在想知道是否将我的基本 WP URL 设置为 mysite.com 会导致此 RewriteCond %{REQUEST_URI} /feed RewriteRule ^/?(.*)$ http://photoboothowners.com/feed [L]
    • 我没有使用过 WordPress,但我知道其他 CMS 有自己的 https 设置,可以独立于 Apache 重写。您可以针对 https 重定向规则采取的一种故障排除步骤是在重定向规则之前将 /feed/forum 拆分为单独的规则。最终它们会像RewriteRule ^feed.* - [L],意思是“不要弄乱以提要开头的任何东西”,但是为了进行故障排除,您会将它们重定向到明显的地方,这样您就可以确保它们匹配,(例如 RewriteRule ^feed.* google.com [R=301, L]`)。
    • 我认为你是对的大卫,因为在使用你的第一个建议时,它仍然使用 https 重定向到我的主页。使用您的第二个建议时,我收到 500 错误。
    • 糟糕...如果第二个建议,您的意思是 google.com 重写,我一定是无意中缩写了它,它需要完整的 URL,例如:RewriteRule ^feed.* http://www.google.com [R=301, L]
    猜你喜欢
    • 2014-06-19
    • 2012-02-02
    • 2013-04-28
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多