簡體   English   中英

如何使用漂亮的URL將HTTP重定向到HTTPS?

[英]How to redirect HTTP to HTTPS with pretty urls?

我想將進入Webfaction托管的Wordpress網站的用戶從HTTP重定向到HTTPS,同時支持漂亮的URLS。 如何實現呢? 我已經嘗試了幾種解決方法,但是沒有用。 (以下示例)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#This is first attempt
#RewriteCond %{HTTPS} =off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L] #Tested here some flags, no success

#This is second attempt
#RewriteCond %{HTTPS} =off
#RewriteRule ^(.*)$ - [env=ps:https]

#This is third attempt
#RewriteCond %{SERVER_PORT} ^([0-9]+s)$
#RewriteRule ^(.*)$ - [env=ps:https]

#This is fourth try
#RewriteCond %{HTTPS} =off
#SSLOptions +StrictRequire
#SSLRequireSSL
#SSLRequire %{HTTP_HOST} eq "example.com"

#This is fifth attempt
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# This is Wordpress pretty URLS (Has to stay!)
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

我所得到的只是重定向循環(301或302)或帶有“在這里找到”的頁面,其中“這里”是我的域的錨點:/忘了,我只能編輯.htaccess。

我找到了這個答案https://serverfault.com/a/678402/102060 ,這對我有所幫助。 事實證明,Webfaction使用某種負載平衡器,該負載平衡器不會通過發送特定的標頭來顯示自身。 我嘗試過這種盲折,它可以工作!

### Force HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM