wordpress - 使用 .htaccess 将 HTTP 重定向到 HTTPs

标签 wordpress .htaccess http redirect https

我试过了this post ,以及许多其他( 1234 ),但它们都给我 TOO_MANY_REDIRECTS 或错误 500。所以,这是我的问题:

使用我当前的 .htaccess,会发生以下情况:

https://www.dukescasino.com/ - 完美运行

https://dukescasino.com/ - 重定向到上面很棒

下面的两个选项加载正常,但它应该重定向到 https 版本:

http://www.dukescasino.com/

http://dukescasino.com/

这是当前的 .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>

我不认为它是相关的,但如果是这样,这里是当前事件插件的列表:

  • 高级自定义字段
  • 多合一 SEO 包
  • 导航菜单的 Bop 搜索框项目类型
  • 联系表格 7
  • 禁用评论
  • Google XML 站点地图
  • WordPress.com 的 Jetpack
  • 搜索和过滤
  • slider WD
  • TablePress
  • UpdraftPlus - 备份/恢复
  • Wordfence 安全
  • WPide
  • 可湿性粉剂
  • WP super 缓存

执行的测试:

测试 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 Internal Server Error 错误。

最佳答案

在 Dreamhost 上,这有效:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{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>

关于wordpress - 使用 .htaccess 将 HTTP 重定向到 HTTPs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32049820/

相关文章:

php - Wordpress, slider 中的最新帖子

php - "Your Projects"中的链接在 WAMP 服务器中不起作用

c++ - Visual C、WinSock HTTP Req 和非 Windows

php - Woocommerce 产品变体、Google 产品提要和 Wordpress 中的嵌套循环

javascript - 自定义 WordPress 管理菜单 : How to make it editable for editors?

html - WordPress 问题

html - 如何将 404 重定向到 index.html 并将 URL 重写为主页 URL?

php - mod_rewrite 用法

android - Android HTTP POST 问题

rest - Angular2 REST API