简体   繁体   English

Wordpress(在Rackspace服务器上)通过一页强制通过SSL强制整个站点,只有一页

[英]Wordpress (on Rackspace Server) force the entire site over SSL except one page

I have a Wordpress site on a Rackspace Cloud Sites server and I currently have both the url and admin url set to the https version of the site. 我在Rackspace Cloud Sites服务器上有一个Wordpress网站,目前我将url和admin url都设置为该网站的https版本。 In addition, I have the following code setup in the htaccess file to direct all pages to be over https . 另外,我在htaccess文件中设置了以下代码,以指示所有页面都通过https

RewriteEngine On
RewriteBase /
#Force SSL on entire site
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://frla.org/$1 [R=301,L]

This code works but now I need one page ( /example-page ) to redirect to the http url because we have to include embed code from a third party that does not have an https version of the site. 这段代码有效,但是现在我需要一个页面( /example-page )重定向到http url,因为我们必须包括来自没有该站点的https版本的第三方的嵌入代码。 I tried the following code but it just redirects to the home page of the site. 我尝试了以下代码,但它仅重定向到网站的主页。

RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{REQUEST_URI} !^\/example-page\/
RewriteCond %{REQUEST_URI} !^\/example-page\/
RewriteRule ^(.*)$ https://frla.org/$1 [R=301,L]

RewriteCond %{ENV:HTTPS} on [NC]
RewriteCond %{REQUEST_URI} \/example-page\/ [OR]
RewriteCond %{REQUEST_URI} \/example-page\/
RewriteRule ^(.*)$ http://frla.org/$1 [R=301,L]

I think it has something to do with the fact that the main Wordpress URL setting is set to https . 我认为与Wordpress的主要URL设置设置为https I appreciate any help you can give me. 感谢您能给我的任何帮助。

Panama Jack, This is my full htaccess file after trying what you suggested. 巴拿马杰克,尝试您的建议后,这是我的完整htaccess文件。 I get an endless loop error for the entire site. 我收到整个网站的无限循环错误。 The middle bottom of this document are all the redirects we had to setup for old pages to direct to the new pages, just fyi. 本文档的中间底部是我们必须设置的所有重定向,以便将旧页面定向到新页面,仅供参考。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Force SSL on entire site
#RewriteCond %{ENV:HTTPS} !on [NC]
#RewriteRule ^(.*)$ https://frla.org/$1 [R=301,L]

RewriteCond %{HTTPS} !^on
RewriteRule ^((?!bill-tracker/?$).*)$ https://frla.org/$1 [R=301,L]

RewriteCond %{HTTPS} ^on
RewriteRule ^(bill-tracker/?)$ http://frla.org/$1 [R=301,L]


#Redirect Specific Pages
RedirectMatch 301 /frla-news/item/1477-2015-florida-minimum-wage-announced https://www.frla.org/news-release/frla-endorses-governor-rick-scott-for-november-2014-election/

RedirectMatch 301 /membership/membership-directory/map https://www.frla.org/member-directory/

RedirectMatch 301 /calendar/flat https://www.frla.org/events/

RedirectMatch 301 /membership-form https://www.frla.org/membership/join

RedirectMatch 301 /about/4-training-certification https://www.frla.org/government-relations

Redirect 301 /faq https://www.frla.org/about/faqs

Redirect 301 /endless-summer-music-series-and-events https://www.frla.org/endless-summer-music-series-events/

RedirectMatch 301 /frla-news/item/551-tip-outs-and-tip-pooling https://www.frla.org/news-release/tip-outs-and-tip-pooling

RedirectMatch 301 /about/item/127-ceo-profile-carol-dover https://www.frla.org/leadership/

RedirectMatch 301 /educational-foundation/item/198-prostart-school-to-career-program https://www.frla.org/educational-foundation/prostart/

RedirectMatch 301 /frla-news/item/1491-chef-emeril-lagasse-highlights-special-occasion-restaurants-in-florida-on-national-tv https://www.frla.org/news-release/chef-emeril-lagasse-highlights-special-occasion-restaurants-in-florida-on-national-tv-2/

RedirectMatch 301 /frla-news/item/1501-hundreds-of-florida-high-school-students-showcase-culinary-arts-and-restaurant-management-skills-at-statewide-competition https://www.frla.org/news-release/hundreds-of-florida-high-school-students-showcase-culinary-arts-and-restaurant-management-skills-at-statewide-competition/

RedirectMatch 301 /frla-news/item/1502-chef-emeril-lagasse-tours-downtown-restaurants-in-the-sunshine-state-on-latest-episode-of-emerils-florida https://www.frla.org/news-release/chef-emeril-lagasse-tours-downtown-restaurants-in-the-sunshine-state-on-latest-episode-of-emerils-florida-2/

RedirectMatch 301 /frla-news/item/1500-frlas-broward-chapter-raises-funds-to-support-hospitality-education-for-local-high-school-students https://www.frla.org/frla-news/item/1500-frlas-broward-chapter-raises-funds-to-support-hospitality-education-for-local-high-school-students

RedirectMatch 301 /frla-news/item/1498-florida-restaurant-and-lodging-associations-pinellas-chapter-installs-new-officers-and-board-of-directors-for-2015 https://www.frla.org/news-release/64863/

RedirectMatch 301 /frla-news/item/1503-panama-city-beach-businesses-community-leaders-and-law-enforcement-prepare-for-safe-and-successful-spring-break-at-hospitality-workshop https://www.frla.org/news-release/panama-city-beach-businesses-community-leaders-and-law-enforcement-prepare-for-safe-and-successful-spring-break-at-hospitality-workshop-2/

RedirectMatch 301 /frla-news/item/1505-rep-harrison-and-sen-abruzzo-file-bill-to-spur-economic-development https://www.frla.org/news-release/rep-harrison-and-sen-abruzzo-file-bill-to-spur-economic-development/

RedirectMatch 301 /frla-news/item/1410-chef-emeril-lagasse-visits-central-florida-farm-to-table-restaurant-and-egg-farm-in-latest-emerils-florida-television-episode- https://www.frla.org/news-release/chef-emeril-lagasse-visits-central-florida-farm-to-table-restaurant-and-egg-farm-in-latest-emerils-florida-television-episode/

RedirectMatch 301 /frla-news/item/1420-chef-emeril-lagasse-samples-restaurants-in-south-walton-county-on-latest-emerils-florida-tv-episode https://www.frla.org/news-release/chef-emeril-lagasse-samples-restaurants-in-south-walton-county-on-latest-emerils-florida-tv-episode/

RedirectMatch 301 /images/2014_Florida_Tourism_Day_Registration_Form.pdf https://www.frla.org/wp-content/uploads/2015/05/2014_Florida_Tourism_Day_Registration_Form.pdf

RedirectMatch 301 /frla-news/item/1433-gov-scott-another-record-year-for-florida-tourism https://www.frla.org/news-release/gov-scott-another-record-year-for-florida-tourism/

RedirectMatch 301 /frla-news/item/1434-frla-members-donate-reusable-inventory-to-the-florida-department-of-corrections https://www.frla.org/news-release/frla-members-donate-reusable-inventory-to-the-florida-department-of-corrections/

RedirectMatch 301 /images/stories/GR/FRLA_2014_Legislative_Scorecard.pdf https://www.frla.org/wp-content/uploads/2015/05/FRLA_2014_Legislative_Scorecard.pdf

RedirectMatch 301 /events/board-meetings https://www.frla.org/board-meetings/

RedirectMatch 301 /frla-news/item/1464-food-network-and-travel-channel-personalities-to-headline-florida-restaurant-and-lodging-associations-marketingoperations-summit https://www.frla.org/news-release/food-network-and-travel-channel-personalities-to-headline-florida-restaurant-and-lodging-associations-marketingoperations-summit/

RedirectMatch 301 /frla-news/item/1466--state-implements-new-food-service-inspection-frequency https://www.frla.org/news-release/state-implements-new-food-service-inspection-frequency/

RedirectMatch 301 /frla-news/item/1467-the-florida-restaurant-and-lodging-association-strengthens-efforts-in-palm-beach-by-welcoming-new-chapter-director- https://www.frla.org/news-release/the-florida-restaurant-and-lodging-association-strengthens-efforts-in-palm-beach-by-welcoming-new-chapter-director/

RedirectMatch 301 /frla-news/item/1468-hospitality-industry-executives-share-secrets-of-success-at-frlas-marketingoperations-summit https://www.frla.org/frla-news/item/1468-hospitality-industry-executives-share-secrets-of-success-at-frlas-marketingoperations-summit

RedirectMatch 301 /frla-news/item/1472-frlas-regulatory-compliance-services-welcomes-new-northwest-florida-regional-manager https://www.frla.org/news-release/frlas-regulatory-compliance-services-welcomes-new-southeast-florida-regional-sales-manager/

RedirectMatch 301 /frla-news/item/1471-frla-endorses-governor-rick-scott-for-november-2014-election https://www.frla.org/news-release/frla-endorses-governor-rick-scott-for-november-2014-election/

RedirectMatch 301 /frla-news/item/1473-gov-scott-florida-tourism-on-pace-for-another-record-year- https://www.frla.org/news-release/gov-scott-florida-tourism-on-pace-for-another-record-year/

RedirectMatch 301 /frla-news/item/1474-endless-summer-music-series-brings-nashvilles-top-songwriters-to-destin-florida-for-free-concerts https://www.frla.org/news-release/endless-summer-music-series-brings-nashvilles-top-songwriters-to-destin-florida-for-free-concerts/

RedirectMatch 301 /frla-news/item/1486-frlas-tallahassee-chapter-installs-new-officers-and-board-of-directors-for-2015 https://www.frla.org/news-release/frlas-tallahassee-chapter-installs-new-officers-and-board-of-directors-for-2015/

RedirectMatch 301 /frla-news/item/1487-frlas-broward-chapter-installs-new-officers-and-board-of-directors-for-2015 https://www.frla.org/news-release/frlas-broward-chapter-installs-new-officers-and-board-of-directors-for-2015/

RedirectMatch 301 /frla-news/item/1485-frlas-palm-beach-chapter-installs-new-officers-and-board-of-directors-for-2015 https://www.frla.org/news-release/frlas-palm-beach-chapter-installs-new-officers-and-board-of-directors-for-2015/

RedirectMatch 301 /frla-news/item/1513-chef-emeril-lagasse-tours-family-owned-and-operated-restaurants-on-latest-episode-of-emerils-florida https://www.frla.org/news-release/chef-emeril-lagasse-tours-family-owned-and-operated-restaurants-on-latest-episode-of-emerils-florida-2/

RedirectMatch 301 /frla-news/item/1519-frlaef-announces-winners-of-hospitality-and-tourism-management-program-competition https://www.frla.org/news-release/frlaef-announces-winners-of-hospitality-and-tourism-management-program-competition/

RedirectMatch 301 /frla-news/item/1520-chef-emeril-lagasse-tours-kissimmee-on-latest-episode-of-emerils-florida https://www.frla.org/news-release/64807/

RedirectMatch 301 /educational-foundation/item/198-prostart-school-to-career-program https://www.frla.org/educational-foundation/prostart/

RedirectMatch 301 /educational-foundation/item/200-lodging-management-program https://www.frla.org/educational-foundation/htmpstart/

RedirectMatch 301 /frla-news/item/1529-member-spotlight-focus-on-guest-experiences-fuels-sustained-turnaround-at-steak-n-shake https://www.frla.org/news-release/member-spotlight-focus-on-guest-experiences-fuels-sustained-turnaround-at-steak-n-shake/

RedirectMatch 301 /frla-news/item/1530-nashvilles-top-songwriters-to-help-raise-money-for-childrens-charities-at-south-walton-beaches-wine-a-food-festival https://www.frla.org/news-release/nashvilles-top-songwriters-to-help-raise-money-for-childrens-charities-at-south-walton-beaches-wine-food-festival-2/

RedirectMatch 301 /frla-news/item/1532-more-than-150-songwriters-head-to-southernmost-point-for-20th-annual-festival-may-6-10-2015 https://www.frla.org/news-release/more-than-150-songwriters-head-to-southernmost-point-for-20th-annual-festival-may-6-10-2015/

RedirectMatch 301 /images/M_images/frla%202015%20legislative%20scorecard_updated.pdf https://www.frla.org/wp-content/uploads/2015/05/frla-2015-legislative-scorecard_updated1.pdf

RedirectMatch 301 /frla-news/item/1537--tallahassee-restaurants-to-offer-fantastic-food-at-mouth-watering-prices-during-capital-cuisine-restaurant-week-and-concert-series-may-14-26 https://www.frla.org/news-release/release-1/

RedirectMatch 301 /frla-news https://www.frla.org/newsroom

</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?uploads/wpjobboard/application/(.+) /wp-content/plugins/wpjobboard/restrict.php?url=application/$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

You can try this rule for your .htaccess. 您可以为.htaccess尝试使用此规则。 if you want to exclude example-page from https redirection. 如果要从https重定向中排除example-page Replace your current rule. 替换当前的规则。

RewriteCond %{HTTPS} !^on
RewriteRule ^((?!example-page/?$).*)$ https://frla.org/$1 [R=301,L]

RewriteCond %{HTTPS} ^on
RewriteRule ^(example-page/?)$ http://frla.org/$1 [R=301,L]

First, thank you for all of your help. 首先,感谢您的所有帮助。 I really appreciate it. 我真的很感激。 Just in case it helps anyone else I wanted to post the answer I came up with. 以防万一它有助于我想发布答案的其他任何人。

Instead of doing the redirect in the htaccess file I removed all of that code and setup my own Wordpress function in the functions.php file. 我没有在htaccess文件中进行重定向,而是删除了所有代码,并在functions.php文件中设置了自己的Wordpress函数。 Also, in the Wordpress settings I set the Wordpress URL to be the https version (this controls how files are uploaded, which we need to be over https) but I set the Site URL to be the http version. 另外,在Wordpress设置中,我将Wordpress URL设置为https版本(这控制文件的上传方式,我们需要通过https),但将Site URL设置为http版本。 This is the function I wrote to handle the redirects... 这是我编写的用于处理重定向的功能...

function force_https () {
    $addr = $_SERVER['HTTP_HOST'];
    $production_site = true;

    if(preg_match('/localhost/', $addr) || preg_match('/developmentserver.com/', $addr)){
        $production_site = false;
    }

    //only redirect to SSL if it is on the production server.
    if($production_site == true){
        if ( !is_ssl() && !is_page('bill-tracker') ) {
        wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
        exit();
        }
        elseif (is_ssl() && is_page('bill-tracker')) {
            wp_redirect('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
            exit();
        }
    }
}

//only enable for production sites
add_action ( 'template_redirect', 'force_https', 1 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM