.htaccess 以在忽略扩展名后重定向到文件夹


.htaccess to redirect to folder after ignoring the extension

我的要求是应该重定向URL,如下所述

http://mysite.com/page1.html ==> http://mysite.com/page1http://mysite.com/page2.html ==> http://mysite.com/page2

在上面的示例中,page1/page2 是根目录中的文件夹,应从 page1.html 或 page2.html 重定向。

任何人都可以为以下解决方案提供解决方案或增强功能。

我正在尝试使用以下语法。

Redirect permanent http://mysite.com/page1.html http://mysite.com/page1

尝试:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.*)'.html$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*)'.html$ /$1/ [L,R=301]

您需要使用THE_REQUEST变量。

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+([^.]+)'.html[^'s?] [NC]
RewriteRule ^ /%1? [R=301,L]