2015-06-25 24 views
1

我在Rackspace Cloud Sites服務器上有一個Wordpress站點,並且我目前已將url和admin url設置爲該站點的https版本。此外,我在htaccess文件中設置了以下代碼,以指示所有頁面超過httpsWordpress(在Rackspace服務器上)通過SSL強制整個站點通過SSL,但一頁除外

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

此代碼的工作,但現在我需要一個頁面(/example-page)重定向到URL http因爲我們要包括從第三方嵌入代碼,不具有https版本的網站。我嘗試了下面的代碼,但它只是重定向到網站的主頁。

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] 

我認爲這是與主WordPress的URL設置爲https的事實。我很感激你能給我的任何幫助。

巴拿馬傑克,這是我的完整htaccess文件後,嘗試你的建議。我得到了整個網站無盡的循環錯誤。本文檔的中間部分是我們必須爲舊頁面設置的所有重定向,以指向新頁面,只是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 
+0

你想排除一個頁面還是一個目錄?還需要重定向到那個? –

+0

我只想排除一個頁面。是的,如果通過https訪問它,它需要重定向到http版本。 – joenammo

+0

你試過我提供的答案嗎? –

回答

1

首先,非常感謝您的幫助。對此,我真的非常感激。以防萬一它幫助其他人發佈我想出的答案。

而不是做在htaccess文件中的重定向,我刪除了所有的代碼,並在functions.php文件中設置我自己的Wordpress函數。另外,在Wordpress設置中,我將Wordpress URL設置爲https版本(這控制着如何上傳文件,我們需要通過https),但是我將網站URL設置爲http版本。這是我寫的處理重定向的功能...

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); 
1

您可以嘗試此規則爲您的.htaccess。如果您想要從https重定向中排除example-page。替換您當前的規則。

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]