单独的CodeIgniter公用文件夹

编程入门 行业动态 更新时间:2024-10-27 22:30:59
本文介绍了单独的CodeIgniter公用文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试更改CodeIgniter文件的结构,以使其更安全,更干净,但我无法使其正常工作。我想将用户可见的应用程序/系统和公共文件分开。

I've been trying to change my CodeIgniter file structure to make it safer and cleaner but I can't get it to work. I want to separate the application/system and the public files that are going to be visible to users.

- application - system - public

它可行,但我必须输入

example/public/index.php或example/public/controller

example/public/index.php or example/public/controller

我希望能够像example/controller这样输入基本URL。

I want to be able to just type the base URL like example/controller.

我该怎么做?

推荐答案

对于CodeIgniter 3.x,正确的处理方式(在2018年及之后)如下:

For CodeIgniter 3.x, the correct way to approach this (at this point in 2018 and after) is as follows:

  • 在根文件夹中创建公用文件夹
  • 移动您的index.php文件到该文件夹​​中(以防止歧义)
  • 在已移动的index.php文件中,更改以下内容: 将 $ system_path 更改为 ../ system 更改 $ application_folde r 到 ../ application
  • Make a public folder in your root folder
  • MOVE your index.php file into this folder (to prevent ambiguity)
  • inside the moved index.php file, change the following: change $system_path to ../system change $application_folder to ../application

现在,我们需要一个 .htaccess 文件,但是默认情况下CI 3.x没有.htaccess文件,所以..如何从CI窃取它4.x默认情况下有哪个?您可以在这里找到它:

Now, we need an .htaccess file, but CI 3.x doesn't have a .htaccess file by default, soo.. how about stealing it from CI 4.x which has it by default? You can find it here:

github/bcit-ci/CodeIgniter4/blob/develop/public/.htaccess

我建议您不要包括 SetEnv CI_ENVIRONMENT开发行-而是在您的apache或NGinx .conf文件中定义此行,以便.htaccess文件可以在任何地方使用。

I recommend you NOT include the line SetEnv CI_ENVIRONMENT development - instead, define this in your apache or NGinx .conf file so the .htaccess file can work anywhere.

最后,您需要更新.conf文件,以便将 DOCUMENT_ROOT 设置为名为public的子文件夹(或您选择的命名方式) 。然后重新启动Apache / Nginx。

Finally, you'll meed to update your .conf file so that DOCUMENT_ROOT is set to the subfolder named public (or whatever you chose to name it). Then restart Apache/Nginx.

那应该给您相同的结果,并且更加安全。

That should give you the same results, and be much more secure.

-更新-我发现我对CI 4中的 .htaccess 文件有问题,但是怀疑是我的系统出了问题。但是,这个简单的版本确实有效:

-- UPDATE -- I found that I had problems with the .htaccess file from CI 4, however suspect it's my system that's the problem. This simple version did work however:

RewriteEngine on RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png) RewriteCond %(REQUEST_FILENAME) !-f RewriteCond %(REQUEST_FILENAME) !-d RewriteRule ^(.*)$ ./index.php/$1 [L]

更多推荐

单独的CodeIgniter公用文件夹

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

发布评论

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

>www.elefans.com

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