.htaccess - 将 http 重定向到 https 在子目录中出现问题 404 - 未找到

标签 .htaccess redirect mod-rewrite url-rewriting friendly-url

根文件夹中的 htaccess

#<IfModule mod_rewrite.c>
#RewriteEngine On
#Uncomment these two lines If you want to redirect http to https
#RewriteCond %{HTTPS} off
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php [L]
#</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^https://3pmix.com/ [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

子文件夹中的htaccess

RewriteRule ^classes/.*$ - [F,L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} config.php|db.php|functions.php [NC]
RewriteRule .* - [F,L]

通过图像的目录结构

enter image description here

最佳答案

对于您显示的示例,请尝试以下规则文件。另外,请确保在测试 URL 之前清除浏览器缓存。

让您的根 htaccess 规则文件如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^3pmix\.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
</IfModule>

并让您的子目录 htaccess 规则文件如下:

RewriteOptions InheritBefore
RewriteEngine ON
RewriteRule ^classes - [NC,F,L]
RewriteRule (?:config\.php|db\.php|functions\.php) - [NC,F,L]

我还在您的 htaccess 文件中修复了标志和正则表达式。

关于.htaccess - 将 http 重定向到 https 在子目录中出现问题 404 - 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66928641/

相关文章:

node.js - 解析托管静态文件 URL 别名

.htaccess - RewriteRule ^(.*)$ 与 RewriteRule (.*)$ 的区别

php - 用户登录被重定向到 index.php

php - 在 php 脚本中访问重写的 URI

regex - 通过 htaccess 将部分添加到 URL

重写我的 htaccess 后,Php PDO 和 Get 方法无法在干净的 URL 中工作

php - 拒绝访问 .htaccess 中的 .ini 文件是否安全?

apache - 将 Docker 容器应用程序与现有的 Apache Web 服务器连接

javascript - 5 秒后重定向,但只允许引用者访问该页面

php - 在 Windows 上使用 .htaccess 进行 URL 重写