更新时间:2023-02-23 19:52:41
说明:http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
示例:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/$ $1.html
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
然后,所有超链接、css 链接、图像等都需要更新为绝对 URL (http://www.site.com/style.css
) 或相对 URL并以 ../
开头.否则会遇到 CSS 无法加载、链接无效等问题.
Then, all hyperlinks, css links, images, etc, will need to be updated to have either an absolute URL (http://www.site.com/style.css
) or relative and begin with ../
. Otherwise you will encounter issues such as CSS that doesn't load, links that don't work, etc.