首先安装好 apache 后,启用 rewrite 功能
$ a2enmod rewrite
然后再到 /etc/apache2/apache2.conf
添加内容
$ nano /etc/apache2/apache2.conf
内容为
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted</Directory>
记得将路径设为你的网站根目录路径呦!
接着将 apache reload
service apache2 reload
然后去你的网站根目录中添加档案为 .htaccess,并加入以下内容
Options -IndexesOptions +FollowSymlinksRewriteEngine on
在同一个 .htaccess
档案中添加 RewriteRule,就像这样
Options -IndexesOptions +FollowSymlinksRewriteEngine onRewriteRule ^admin/index$ admin/index.php
这样只要访问路径 /admin/index
就等于是访问了 /admin/index.php
,apache已经帮你隐藏副档名了
参考
https://ianakaberlin.medium.com/apache-%E7%B6%B2%E9%A0%81%E4%BC%BA%E6%9C%8D%E5%99%A8-%E9%80%8F%E9%81%8E-htaccess-%E9%9A%B1%E8%97%8F%E7%B6%B2%E5%9D%80%E7%9A%84-php-%E5%89%AF%E6%AA%94%E5%90%8D-mod-rewrite-php-apache-%E4%BC%8A%E6%81%A9%E8%B8%A9%E5%9D%91%E7%AD%86%E8%A8%98-3d6a4b80d223