请不要推荐我带有超过173个upvotes的long and very detailed thread。它不适合我。我也尝试了很多其他的(1,2,3,4)。他们都让我TOO_MANY_REDIRECTS或错误500。所以,这里是我的问题:使用.htaccess将HTTP重定向到HTTP
从我目前的.htaccess,这是发生了什么:
https://www.dukescasino.com/ - 完美的作品
https://dukescasino.com/ - 重定向到其上方是伟大的
两个以下负载选项罚款,但应重定向到HTTPS版本:
这是当前的.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>
我不认为这是相关的,但即便如此,这里是当前活跃的插件列表:
- 高级定制域
- All In One SEO包
- Bop搜索框项目类型For导航菜单
- 联系表7
- 禁用评论
- 谷歌的XML的Sitemaps
- 的Jetpack采用WordPress。COM
- 搜索&筛选
- 滑块WD
- TablePress
- UpdraftPlus - 备份/恢复
- Wordfence安全
- WPide
- WP斯马什
- 可湿性粉剂超高速缓存
编辑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
试验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内部服务器错误错误。
也许只是一个错字,但是你拼写'.htaccess'错误(同样的方式)3次?您当前的.htaccess文件不完整,您缺少'RewriteEngine On'指令。大概,当你添加规范重定向时,你将这个添加到你的.htaccess文件的最顶部?你声明'https:// example.com'重定向好,但是,这不是在你的配置文件中指出的?这是怎么发生的?知道你实际尝试过的东西是有用的 - 这是行不通的。 – MrWhite
对不起,.htaccess是一个错字,我现在修复了。我还更新了当前的.htaccess代码以及我对每个结果所做的所有测试。我不知道没有www的https如何重定向到https:// www版本。谢谢 –
您通常会期望设置服务器变量“HTTPS”(否则您的结果会显示)。你是否支持代理? (测试E很可能会导致某种“递归”的404?) – MrWhite