无法访问 CodeIgniter 控制器

CodeIgniter controllers unreachable

我使用 Xampp 和 CodeIgniter 开发了一个网络应用程序。处理干净路由的最佳方法是将 VirtualHost 设置为指向包含 xampp/apache/conf/httpd.conf 中项目的文件夹,然后使用 route.php 文件中的路由,例如

$route['page1'] = "Page1Controller/page1Function";

我使用 href 或 header 像这样使用 root 作为基础文件夹:

href="/page1"

所有这些在本地都运行良好,我从不使用 base_url() 或类似的功能。

切换到生产服务器,我显然除了我的个人文件夹和子文件夹没有任何权限所以当我执行它时,根文件夹成为所有域的根,而不仅仅是我的项目文件夹。

我试过 base_url() 但它不起作用,找不到页面,即使不使用 $route

有没有一种方法可以在不重构代码中的所有链接的情况下处理这个问题,或者有什么方法可以通过重构来解决这个问题?

编辑

我现在使用 "./page1" 来访问 index.php 文件夹的位置,而不是使用 "/page1"。但是,我仍然无法使用 php 或 html/js 访问其他页面。

假设路由在本地运行,以下是我为使其适应生产服务器而采取的步骤。

1 - 控制器和视图的首字母大写

CodeIgniter 要求在控制器和视图的命名中使用大写字母,因此即使路由在 Windows、Linux case-sensitivity 中都需要正确的命名class 标题和 routes.php 文件中的引用。

2 - 使用 './' 而不是 '/'

因为应用程序的部署发生在子域中,所以根对应于域本身,而不是 index.php 所在的子域,并且可以通过 './' (cf. SO question) 访问。

3 - .htaccess 文件中的硬编码子域路径

在此 doc 之后,我执行了一些步骤来更正标准 .htaccess 文件,使其与服务器上的 sub-directory 一起工作。标准变体只是从这条规则中删除 '/' :

RewriteRule ^(.*)$ /index.php/ [L]

这导致

RewriteRule ^(.*)$ index.php/ [L]

然而,这并没有在我的服务器上解决它,我不得不硬编码路径:

If you are running EE from a sub-directory and it still doesn’t work after removing the slash, you may need to specify the sub-directory in your rewrite rule. For example, if your sub-folder is named testing, change:

RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]

To:

RewriteRule (.*?)index\.php/*(.*) testing/ [R=301,NE,L]

And change:

RewriteRule ^(.*)$ /index.php/ [L]

To:

RewriteRule ^(.*)$ testing/index.php/ [L]