【问题标题】:htaccess PHP MVC Redirect to httpshtaccess PHP MVC 重定向到 https
【发布时间】:2017-07-13 05:15:11
【问题描述】:

我的 htacess 文件有问题。

我有一个 php mvc 系统,根目录看起来像 公共[文件夹] 应用程序 [文件夹] 访问

第一个htaccess读取

RewriteEngine on 

RewriteRule ^$ public/ [L]

RewriteRule (.*) public/$1 [L]

这是从我假设的 url 中删除 public ?

我拥有的第二个 htaccess 文件位于公共目录中,其中包含启动 php 应用程序的 index.php 文件

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^/public) /$1 [L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

这是为了强制 url 转到 https 而不是 http,我遇到的问题是,如果将 url 作为http://example.com 输入到 url 栏中并且重写发生,它将带我到 https://example.com/public,如果发生这种情况,我正在尝试从 url 中删除公共目录,任何帮助都会非常感激。

干杯 瑞恩

【问题讨论】:

  • 非常感谢,我什至没有考虑将文档根设置为公开。写这个作为答案并且我不接受它,我一直很愚蠢(第一个 MVC 应用程序)
  • 添加评论作为答案

标签: php apache .htaccess mod-rewrite


【解决方案1】:

重写不会删除部分或更改用户浏览器中的 URL。

第一个 htaccess 只是简单地向 / 发出所有请求,在内部从 /public 文件夹加载文件,而不会引起用户注意。

如果您不希望/public 可用,则应将文档根目录更改为指向公用文件夹而不是上面的文件夹。

【讨论】:

  • 干杯伙伴:)。
猜你喜欢
  • 2017-09-16
  • 1970-01-01
  • 2014-05-30
  • 2022-01-11
  • 2013-06-30
  • 2021-11-10
  • 2012-12-23
  • 2020-07-11
相关资源
最近更新 更多