Home  >  Article  >  Backend Development  >  How to remove index.php

How to remove index.php

藏色散人
藏色散人Original
2020-08-22 09:12:243405browse

去掉index.php的方法:首先找到Apache配置文件httpd.conf;然后在该文件中去掉“LoadModule rewrite_module modules/mod_rewrite”前面的“#”号即可。

How to remove index.php

推荐:《PHP视频教程

网站当中的index.php往往会让恶意用户得到过多的项目细节信息,去掉网站链接中的index.php,可以大大提高网站的安全性。本文针对Apache服务器下如何配置,才能在访问网站时隐藏index.php。

已有Apache+PHP的服务器环境,并且有一个可以运行的项目。

方法/步骤

找到Apache配置文件httpd.conf,在该文件中去掉LoadModule rewrite_module modules/mod_rewrite.so前面的“#”号,即开启Apache的url重写模式。

将httpd.conf文件里面的所有AllowOverride None都改为AllowOverride All

创建.htaccess文件并放到项目根目录下。

在这个文件里面加: 

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php/$1 [L]

如果项目支持在配置文件中设置项目的url重写模式,需要在项目的配置文件里写

return Array( 
‘URL_MODEL’ => ’2′, 
);

如果不支持在配置文件中设置url重写模式,该步骤可省略。

注意事项

根据Apache的安装目录,在conf文件夹下找到httpd.conf文件。

The above is the detailed content of How to remove index.php. 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