首先在根目录下新建 .htaccess文件
输入下面的代码
RewriteEngine on
# 这个是apache2.4使用
RewriteRule ^(.+).html /$1 [L,R]
# now we will internally map /file to /file.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)/?$ /$1.html [END]
# 移除.html扩展名 大部分使用这个
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME}.html -f
# RewriteRule ^([^\.]+)$ $1.html [NC,L]
# 如果请求的文件或目录不存在,显示404页面
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.html [L]
附录使用其他的服务器相似配置
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
RewriteRule .* http://localhost/html/%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
RewriteRule .* %1.html [L]
</IfModule>