Home > Backend Development > PHP Problem > How to remove url index.php

How to remove url index.php

藏色散人
Release: 2023-03-09 07:50:01
Original
1758 people have browsed it

去掉url index.php的方法:首先启用mod_rewrite;然后创建htaccess文件,添加内容为“RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]”即可。

How to remove url index.php

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

移除 URL 中的 index.php

默认情况下,你的 URL 中会包含 index.php 文件:

步骤:

1:启用mod_rewrite:在Apache下找到conf下的httpd.conf文件,去掉:LoadModule rewrite_module modules/mod_rewrite.so前面的“#”符号;

2:在 根目录下的.htaccess文件中添加如下内容,如果没有.htaccess文件,那么就手动创建一个文件。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
Copy after login

如果在Codeigniter根目录下你添加了例如:css,js等文件夹,则要加上一句,如:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|images|css|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
Copy after login

【推荐学习:PHP视频教程

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

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template