使用.htaccess将HTTP重定向到HTTP

编程入门 行业动态 更新时间:2024-10-21 10:08:44
本文介绍了使用.htaccess将HTTP重定向到HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请不要向我推荐 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:

www.dukescasino/ - 完美运作

dukescasino/ - 重定向到以上是很好

dukescasino/ - redirects to the above which is great

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

The two options below loads fine, but it should be redirecting to the https version:

www.dukescasino/

dukescasino/

这是当前的.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的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
  • 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 .* %{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. RewriteCond %{HTTP_HOST} !^www\. RewriteRule .* 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 ^.*$ %{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 ^.*$ %{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 (.*) %{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 ^(.*)$ www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L] RewriteCond %{HTTPS} off RewriteRule ^(.*)$ %{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 ^.*$ %{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

本文发布于:2023-10-31 15:54:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!