How to hide php suffix on website

王林
Release: 2023-03-11 15:34:02
Original
2948 people have browsed it

网站隐藏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]
Copy after login

修改apache配置文件:

/usr/local/httpd/conf/httpd.conf
Copy after login

开启rewrite模块:

LoadModule rewrite_module modules/mod_rewrite.so
Copy after login

保证:

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

重启apache:

/usr/local/httpd/bin/apachectl restart
Copy after login

使用浏览器访问:

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!