【问题标题】:redirect http to https making a problem in subdirectory as 404 - Not found将 http 重定向到 https 在子目录中作为 404 出现问题 - 未找到
【发布时间】:2021-06-29 21:01:17
【问题描述】:

根文件夹中的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]

通过图像的目录结构

【问题讨论】:

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


【解决方案1】:

使用您显示的示例,请尝试以下规则文件。还要确保在测试 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 文件中修复了标志和正则表达式。

【讨论】:

  • @mudasirabbasturi,对不起,我没听懂,请尝试您的规则文件,如上所示,如果这有帮助,请告诉我,干杯。
  • 问题没有通过修改再次解决
  • @mudasirabbasturi,这些规则应该可以正常工作,您能否提及您使用的示例网址?
【解决方案2】:

重写基础丢失,这就是为什么找不到网站的根 url

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 2013-05-12
    • 2017-01-01
    • 1970-01-01
    • 2015-09-08
    • 2018-03-30
    • 1970-01-01
    相关资源
    最近更新 更多