請不要推薦我帶有超過173個upvotes的long and very detailed thread。它不適合我。我也嘗試了很多其他的(1,2,3,4)。他們都讓我TOO_MANY_REDIRECTS或錯誤500。所以,這裏是我的問題:使用.htaccess將HTTP重定向到HTTP
從我目前的.htaccess,這是發生了什麼:
https://www.dukescasino.com/ - 完美的作品
https://dukescasino.com/ - 重定向到其上方是偉大的
兩個以下負載選項罰款,但應重定向到HTTPS版本:
這是當前的.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我不認爲這是相關的,但即便如此,這裏是當前活躍的插件列表:
- 高級定製域
- All In One SEO包
- Bop搜索框項目類型For導航菜單
- 聯繫表7
- 禁用評論
- 谷歌的XML的Sitemaps
- 的Jetpack採用WordPress。COM
- 搜索&篩選
- 滑塊WD
- TablePress
- UpdraftPlus - 備份/恢復
- Wordfence安全
- WPide
- WP斯馬什
- 可溼性粉劑超高速緩存
編輯1 - 測試執行:
試驗A:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
結果: ERR_TOO_MANY_REDIRECTS
試驗B:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
結果: ERR_TOO_MANY_REDIRECTS
試驗C:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
結果: ERR_TOO_MANY_REDIRECTS
試驗d:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
結果: ERR_TOO_MANY_REDIRECTS
測試E:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
結果:發現302。此外,嘗試使用ErrorDocument處理請求時遇到500內部服務器錯誤錯誤。
也許只是一個錯字,但是你拼寫'.htaccess'錯誤(同樣的方式)3次?您當前的.htaccess文件不完整,您缺少'RewriteEngine On'指令。大概,當你添加規範重定向時,你將這個添加到你的.htaccess文件的最頂部?你聲明'https:// example.com'重定向好,但是,這不是在你的配置文件中指出的?這是怎麼發生的?知道你實際嘗試過的東西是有用的 - 這是行不通的。 – MrWhite
對不起,.htaccess是一個錯字,我現在修復了。我還更新了當前的.htaccess代碼以及我對每個結果所做的所有測試。我不知道沒有www的https如何重定向到https:// www版本。謝謝 –
您通常會期望設置服務器變量「HTTPS」(否則您的結果會顯示)。你是否支持代理? (測試E很可能會導致某種「遞歸」的404?) – MrWhite