.htaccess文件:添加以下行:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
[HTTPS://Alex次can.com/post/how-to-remove-PHP-HTML-htm-extensions-with-htaccess/]
现在,您必须检查apache2.log文件中的AllowOverride条件:在您的Web根目录中设置选项AllowOverRide All:
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
如果尝试访问不带.php扩展名的网页,则可能在apache error.log文件中遇到以下错误: /var/www/html/web/.htaccess:无效的命令“ RewriteEngine”,可能是拼写错误或由服务器配置中未包含的模块定义的
要解决此问题:您没有安装mod_rewrite模块,要安装它:运行以下命令:ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
.htaccess:无效的命令“ RewriteEngine”,可能是拼写错误或由服务器配置中未包含的模块定义的
同样,刷新网页后,您可能会在error.log文件中得到以下错误:
[negotiation:error] [pid 4650] [client 127.0.0.1:46461] AH00687: Negotiation: discovered file(s) matching request: /var/www/html/web/test (None could be negotiated). (I was trying to access localhost/web/test.php using the url: localhost/web/test)
要修复它,您必须在apache2.conf中添加以下行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .html
AddType application/x-httpd-php-source .phps
[HTTPS://forums.digital point.com/threads/htaccess-add type-application-小-HTTP的-PHP-PHP-htm-HTML-安定-maybe-啊-fix.7584/#post-2491687]
现在,我可以仅使用文件名访问test.php文件:test