【问题标题】:htaccess remove www redirect to ssl but wrong urlhtaccess 删除 www 重定向到 ssl 但错误的 url
【发布时间】:2021-01-17 14:24:50
【问题描述】:

我用 php 创建了一个 mvc 框架。我唯一工作的主文件是 index.php。

通常我会从 http 重定向到 https。我也删除了 www 域,但是当我输入 www 时,如果我的 URL 是例如

domain.com/admin/products/edit/1, 

htaccess 会这样做。

domain.com/index.php/products/edit/1

我该如何解决这个问题 谢谢

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

【问题讨论】:

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


    【解决方案1】:

    您应该有这样的规则,始终将 https 重定向规则放在首位。请在测试您的 URL 之前清除您的浏览器缓存(其余规则来自 OP 的尝试规则 + 我在这里也更改了匹配主机名的正则表达式)。

    RewriteEngine ON
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)(example\.com) [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
    
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    【讨论】:

      猜你喜欢
      • 2014-01-03
      • 2013-10-04
      • 2014-11-24
      • 2017-09-23
      • 2015-02-12
      • 2023-04-03
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      相关资源
      最近更新 更多