0

举一个我所追求的快速示例,这就是我想要的:

example.com/folder/about/  

将向我显示位于以下位置的页面:

example.com/folder/about.html

目前,我的 .htaccess 文件如下所示:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^folder/(.*)$ folder/$1\.html [NC,R=301,L]

当我去:

example.com/folder/about

但不是当我去:

example.com/folder/about/

尝试加载:

example.com/folder/about.html/

这不是文件或目录。

4

1 回答 1

0

您可以%{REQUEST_FILENAME}第二次使用变量,捕获文件名:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
#new line
RewriteCond %{REQUEST_FILENAME}.html .*/(.*)/?
RewriteRule ^folder/ folder/%1 [NC,R=301,L]

更新

把它放在前一个块之前

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^folder/(.*)/ folder/$1 [NC,R=301,L]
于 2013-07-31T12:22:24.017 回答