使用.htaccess将HTTP重定向到HTTP [英] Use .htaccess to redirect HTTP to HTTPs
问题描述
请不要向我推荐 1 ,2 , 3 , 4 )。他们都给了我TOO_MANY_REDIRECTS或错误500.所以,这是我的问题:
Please, don't recommend me the long and very detailed thread with more than 173 upvotes. It didn't work for me. I have also tried many others (1, 2, 3, 4). They all give me TOO_MANY_REDIRECTS or error 500. So, here is my issue:
使用我当前的.htaccess,这就是:
With my current .htaccess, this is what happens:
https://www.dukescasino.com/ - 完美运作
https://dukescasino.com/ - 重定向到以上是很好
https://dukescasino.com/ - redirects to the above which is great
以下两个选项加载正常,但它应该重定向到https版本:
The two options below loads fine, but it should be redirecting to the https version:
< a href =http://dukescasino.com/ =noreferrer> http://dukescasino.com/
这是当前的.htaccess:
Here is the current .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>
我不相信它是相关的,但如果是这样,这里是当前活动插件的列表:
I don't believe it is relevant, but if so, here is the list of current active plugins:
- 高级自定义字段
- All In One SEO Pack
- Bop Search Box项目类型导航菜单
- 联系表格7
- 禁用评论
- Google XML站点地图
- WordPress.com的Jetpack
- 搜索&过滤器
- 滑块WD
- TablePress
- UpdraftPlus - 备份/恢复
- Wordfence安全
- WPide
- WP Smush
- WP Super Cache
- Advanced Custom Fields
- All In One SEO Pack
- Bop Search Box Item Type For Nav Menus
- Contact Form 7
- Disable Comments
- Google XML Sitemaps
- Jetpack by WordPress.com
- Search & Filter
- Slider WD
- TablePress
- UpdraftPlus - Backup/Restore
- Wordfence Security
- WPide
- WP Smush
- WP Super Cache
编辑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
Result: 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
Result: 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
Result: 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
Result: 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内部服务器错误错误。
Result: 302 found. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
推荐答案
问题解决了!
最终.htaccess:
Final .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV: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>
这篇关于使用.htaccess将HTTP重定向到HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!