简体   繁体   English

CodeIgniter | 将index.php移到公用文件夹

[英]CodeIgniter | Move index.php to public folder

I'm new to CodeIgniter and thought could give it a try by 我是CodeIgniter的新手,可以考虑尝试一下

  1. Downloaded the code thats available in CodeIgniter 下载了CodeIgniter中可用的代码
  2. Changed the base url to $config['base_url'] = 'http://localhost:8000'; 将基本网址更改为$config['base_url'] = 'http://localhost:8000';
  3. Started the server using command php -S 0.0.0.0:3000 使用命令php -S 0.0.0.0:3000启动服务器

This went pretty well .Next I tried to move the index.php file to a public folder- and thats when things started breaking. 一切顺利。接下来,我尝试将index.php文件移动到公共文件夹中-那就是事情开始崩溃的时候。

  1. Moved index.php to a newly created public folder 将index.php移动到新创建的公用文件夹
  2. Created a new file public/.htaccess with the below code snippet 使用以下代码段创建了一个新文件public / .htaccess

     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] 
  3. Modified $system_path = '../system'; 修改后的$system_path = '../system'; and $application_folder = '../application' ; $application_folder = '../application' ; in public/index.php . public/index.php

  4. I get a 404 Resource not found , when I try to access the page after restarting the server. 重新启动服务器后尝试访问该页面时,我得到404 Resource not found

Did you change the root folder in the server configuration? 您是否更改了服务器配置中的根文件夹?

If you moved index.php to a different folder, you should have changed the path to index.php in the server settings. 如果将index.php移到另一个文件夹,则应该在服务器设置中将路径更改为index.php。 In the configuration file. 在配置文件中。

this is pretty simple 这很简单

$system_path = __DIR__ . '../system';
$application_folder = __DIR__ . '../application';

and use the normal codeignitor .htacess file and everything runs fine. 并使用正常的codeignitor .htacess文件,一切运行正常。 Symfony does the same in index.php. Symfony在index.php中也做同样的事情。 Of course your css, image, upload folders should be inside the public folder. 当然,您的CSS,图像,上传文件夹应位于公用文件夹内。 then you can remove all index.html files and 然后您可以删除所有index.html文件,

defined('BASEPATH') OR exit('No direct script access allowed');

statements ;) 声明;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM