How to hide the index.php entry file?

coldplay.xixi
Release: 2023-03-02 17:50:01
Original
4311 people have browsed it

php中隐藏index.php入口文件的方法:首先加载【mod_rewrite.so】;然后更改AllowOverride配置;接着添加【.htaccess】文件Rewrite规则;最后更改项目配置文件即可。

How to hide the index.php entry file?

php中隐藏index.php入口文件的方法:

用编辑器打开 Apache 配置文件 httpd.conf(该文件位于 Apache 安装目录Apache2/conf),并按如下步骤修改。

1、加载 mod_rewrite.so

确认加载了 mod_rewrite.so 模块(将如下配置前的 # 号去掉):

LoadModule rewrite_module modules/mod_rewrite.so
Copy after login

2、更改 AllowOverride 配置

更改需要读取.htaccess文件的目录,将原来的目录注释掉:

#
Copy after login

更改 AllowOverride None 为 AllowOverride FileInfo Options ,更改后的配置如下所示:

#

    AllowOverride FileInfo Options
Copy after login

.htaccess 是基于目录来控制的, 该句即表示需要读取.htaccess文件的目录,要根据实际具体 Apache 的解析目录来配置。虚拟主机如果提供 .htaccess 控制,一般都已经配置好了。

3、添加.htaccess文件Rewrite规则

在需要隐藏 index.php 的目录下(本教程中为 E:/html/myapp,也即入口文件所在目录)创建 .htaccess 文件,并写入如下规则代码:


    Options +FollowSymlinks -Multiviews
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
 
Copy after login

如果网站已经有 .htaccess 文件,在里面添加该段配置规则即可。如果不能创建该文件(Windows 平台默认不能创建),你可以下载一个notepad++来进行创建。

4、更改项目配置文件
编辑项目配置文件 Conf/config.php ,将 URL 模式配置为 2(Rewrite模式):

'URL_MODEL' => 2,
Copy after login

至此,各个配置已经完成。保存各配置文件后,重启 Apache 服务器并删除 Runtime 目录下的项目缓存文件,在浏览器访问隐藏 index.php 后的地址测试是否成功:

http://127.0.0.1/html/myapp/Index/index
Copy after login


如果访问成功,那么利用 Apache .htaccess 文件的 Rewrite 规则隐藏 index.php 入口文件的配置就成功了。

相关学习推荐:PHP编程从入门到精通

The above is the detailed content of How to hide the index.php entry file?. 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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!