请注意,我之前错过了添加
我一直在尝试使用 htaccess 清理我的网址,但我看不到让它在我的本地主机上工作。
我的网站网址: localhost/index.html
这是我的 www 文件夹中的默认 htaccess 文件。
#------------------------------------------------------------------------------
# To allow execution of cgi scripts in this directory uncomment next two lines.
#------------------------------------------------------------------------------
AddType application/x-httpd-php .html .htm .php
AddHandler cgi-script .pl .cgi
Options +ExecCGI +FollowSymLinks
将其添加到 Web 根目录/www
目录中的.htaccess
Options +ExecCGI +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L]
现在,http://localhost/page.html
也可以作为http://localhost/page
访问。
请注意,我之前错过了添加
RewriteCond %{REQUEST_FILENAME} !-d
。此条件可确保名为 /page
的任何现有目录不会被 page.html
遮盖。