.htaccess 301重定向和去除.html文件扩展名的结合

3
我正在尝试将stripelatice_ui文件夹中的所有.html文件重定向到根目录,并删除.html扩展名。
localhost:8089/stripelatice_ui/home.html

to

localhost:8089/home

我已经尝试使用。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [QSA,NC,L]


RewriteRule ^stripelatice_ui/(.*)$ /$1 [R=301,NC,L]

但是它给出了错误,说页面存在重定向循环。
1个回答

3

您可以使用:

RewriteEngine On
RewriteBase /stripelatice_ui/

# To externally redirect /stripelatice_ui/file.html to /file
RewriteCond %{THE_REQUEST} /stripelatice_ui/(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/?$ $1.html [L]

实际上我想将/stripelatice_ui/file.html重定向到/file。 - kaustubh badamikar
第一条规则有效,但是无论是/file.html还是/file都没有被服务器处理。它会显示“未找到错误”。 - kaustubh badamikar
我在我的回答中添加了内容,不知道你的.htaccess文件在stripelatice_ui目录中。 - anubhava

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接