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

How to hide index.php in ci framework

藏色散人
Release: 2023-03-06 09:36:01
Original
2654 people have browsed it

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
去掉前面的#
Copy after login
LoadModule rewrite_module modules/mod_rewrite.so
Copy after login

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模块
Copy after login

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>
Copy after login

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
Copy after login

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

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

to:

$config['index_page'] = "";
Copy after login

4. Restart apache and it will be ok.

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template