所以我有这样的页面:
/features.html
我想以
链接到此页面 /features
RewriteEngine on
RewriteRule ^(.*)$ *PATH*.html
文本*PATH*
应采用文件夹路径并向其附加.html
,如果路径以/
结尾
答案 0 :(得分:0)
按照你的逻辑,你到达:
RewriteEngine on
#If path ends in a forward slash, don't rewrite
RewriteRule ^(.*)/$ - [L]
#If path ends in .html, don't rewrite (avoiding an infinite loop)
RewriteRule ^(.*)\.html$ - [L]
#Otherwise add .html to the end (note this will apply to images too)
RewriteRule ^(.*)$ $1.html
但这会影响其他扩展,例如图像。我建议检查文件是否存在,而不是这样:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.html