Home >Backend Development >PHP Problem >How to hide php suffix on website

How to hide php suffix on website

王林
王林Original
2021-07-15 16:00:233017browse

网站隐藏php后缀的方法:首先在apache服务器下htdocs根目录下创建.htaccess文件,并编辑内容;然后编辑apache配置文件,开启rewrite模块;最后重启apache即可。

How to hide php suffix on website

本文操作环境:centos 7系统、php 7.3&&apache 2、thinkpad t480电脑。

我们先在没有任何设置的情况下访问index.php和index,看看是什么样子:

127.0.0.1/index.php

127.0.0.1/index

How to hide php suffix on website

在apache服务器下htdocs根目录下创建文件.htaccess,编辑以下内容:

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

修改apache配置文件:

/usr/local/httpd/conf/httpd.conf

开启rewrite模块:

LoadModule rewrite_module modules/mod_rewrite.so

保证:

Allowoverride ALL(配置文件有多个,请注意上下文)

重启apache:

/usr/local/httpd/bin/apachectl restart

使用浏览器访问:

127.0.0.1/index

How to hide php suffix on website

相关视频教程分享:php视频教程

The above is the detailed content of How to hide php suffix on website. 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