从apache2上的网页中删除.php文件扩展名,可以通过以下步骤实现:
/etc/apache2/
目录下。httpd.conf
或apache2.conf
,可以使用文本编辑器进行编辑。<Directory>
标签,找到你想要删除.php扩展名的目录所在的<Directory>
块。<Directory>
块内,找到AllowOverride
指令,并确保其值设置为All
。这将允许使用.htaccess文件进行配置。<Directory>
块内,找到DirectoryIndex
指令,并确保其值包含index.php
。例如:DirectoryIndex index.php index.html
。.htaccess
的文件,如果已经存在,请打开它。.htaccess
文件中添加以下代码:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
.htaccess
文件。sudo service apache2 restart
现在,你的Apache2服务器将会自动删除.php文件扩展名。例如,当访问http://example.com/page
时,实际上会加载http://example.com/page.php
的内容。
请注意,这只是一种方法,具体操作可能因服务器配置和环境而有所不同。建议在进行任何更改之前备份配置文件和网页文件。
领取专属 10元无门槛券
手把手带您无忧上云