Home  >  Article  >  Backend Development  >  How to hide index.php in ci framework

How to hide index.php in ci framework

藏色散人
藏色散人Original
2020-09-29 10:36:452592browse

How to hide index.php in the ci framework: first modify the apache configuration file; then create the htaccess file; then modify the Ci configuration file; and finally restart apache.

How to hide index.php in ci framework

Recommended: "PHP Video Tutorial"

1. Modify the apache configuration file

  • Enable rewriting module conf/httpd.conf
去掉前面的#
LoadModule rewrite_module modules/mod_rewrite.so

For Ubuntu, you need to create a soft connection in the mods-enabled folder in the apache installation directory.

Enter /mods-enabled,

  -s ../mods-available/rewrite.load rewrite.load  # 要确保 ../mods-available/rewrite.load 文件存在,不存在需要安装rewrite模块

Note: Under the apache installation directory: mods-available---unenabled modules, mods-enabled----enabled modules

  • AllowOverride None Change to AllowOverride All

You can add the following code at the end of the apache configuration file conf/httpd.conf, or in sites- Create a new .conf file in the enabled folder, with any file name, or you can create a link like mods-enabled/.

Alias /athena "/home/liuqian/workspace/athena/"    # 依据实际情况改为自己的路径<Directory "/home/liuqian/workspace/athena/">   # 依据实际情况改为自己的路径
    Options Indexes MultiViews FollowSymLinks    AllowOverride All    # 主要是这个
    Order allow,deny
    Allow from all</Directory>

Note: In the apache installation directory: sites-available---unloaded configuration file, sites-enabled----loaded configuration file

2. Add .htaccess file

Enter the project folder and create the .htaccess file in the directory where index.php is located

Write the following in the file:

/%{REQUEST_FILENAME} !-%{REQUEST_FILENAME} !- !^(index\.php| index.php

3. Modify the Ci configuration file application/config/config.php

$config['index_page'] = "index.php";

to:

$config['index_page'] = "";

4. Restart apache and it will be ok.

sudo apachectl restart  # 这里是ubuntu的重启命令

The above is the detailed content of How to hide index.php in ci framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn