Maison  >  Article  >  développement back-end  >  Comment masquer le suffixe php sur le site Web

Comment masquer le suffixe php sur le site Web

王林
王林original
2021-07-15 16:00:232890parcourir

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

Comment masquer le suffixe php sur le site Web

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

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

127.0.0.1/index.php

127.0.0.1/index

Comment masquer le suffixe php sur le site Web

在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

Comment masquer le suffixe php sur le site Web

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

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn