.htaccess 删除URL中的.html扩展名

fcwjkofz  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(129)

今天我试图从我的网站中删除html文件扩展名,例如:
example.com/page.htmlexample.com/page
我看了一些教程,但似乎没有工作...我在根目录中创建了.htaccess文件
复制的代码(也尝试了不同的代码):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

它不工作时,我打开我的网站作为文件,与Live Server(VS代码扩展)或实际的网站(托管在Replit)
有什么想法吗,为什么它不工作?任何帮助感激...
请参阅whole repository

x0fgdtte

x0fgdtte1#

余淼应该这样做:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC, L]

相关问题