如何使用漂亮的 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)或带有 'Found here' 的页面,其中 'here' 是我域的锚点:/
忘了说了,我只能编辑.htaccess.
我发现这个答案 https://serverfault.com/a/678402/102060 对我有帮助。
事实证明,Webfaction 使用某种负载均衡器,它不会通过发送特定的 headers 来暴露自己。
我试过这个蒙上眼睛,效果很好!
### Force HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我想将进入我的 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)或带有 'Found here' 的页面,其中 'here' 是我域的锚点:/ 忘了说了,我只能编辑.htaccess.
我发现这个答案 https://serverfault.com/a/678402/102060 对我有帮助。 事实证明,Webfaction 使用某种负载均衡器,它不会通过发送特定的 headers 来暴露自己。 我试过这个蒙上眼睛,效果很好!
### Force HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]