【发布时间】:2016-04-19 04:08:50
【问题描述】:
我想将进入我的 Webfaction 托管 Wordpress 站点的用户从 HTTP 重定向到 HTTPS,同时支持漂亮的 URL。如何做到这一点?我已经尝试了几个解决方案,但它不起作用。 (以下示例)
<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。
【问题讨论】:
-
你为什么不使用插件呢?那里足够了。例如ForceSSL
-
@0x4Dark 该插件是我想省略的不必要的代码。
标签: wordpress apache mod-rewrite https friendly-url