所以我在网站的根文件夹中有一个自定义创建的.html页面(以及WP),我希望能够以标准的Wordpress URL格式打开它,换句话说,末尾没有.html扩展名。
请记住,我对正则表达式或.htaccess一无所知,所以我将给您举一个具体的例子:
当我键入mydomain.com/specialpage
时,我希望它加载mydomain.com/specialpage.html
,但保持原始键入的URL格式(不带扩展名)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(specialpage)/?$ /$1.html [L,NC]
这似乎奏效了。只需要把它放在Wordpress附带的其他默认规则之上。
如果你有多个页面,你可以这样做:
RewriteEngine On
# Check to see if a .html file exists for this request.
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$ # Prevent internal recursion
# If so, then use serve that file.
RewriteRule ^(.+)$ $1.html [NC,L]
关于尾部斜杠的注意事项:您在这里无法做到这一点,因为它会将其包含在请求文件名中,从而检查
specialpage/.html
是否存在,这不是您想要的。