如何重定向文件夹中的所有页面并删除.html前缀

时间:2014-07-21 11:43:56

标签: regex apache .htaccess mod-rewrite redirect

我发现了许多301 htaccess重定向示例,但我需要一些特定的东西,并且不知道如何构建那个确切的重定向规则...我构建的网站是一个wordpress网站。

示例:

http://www.example.com/article/some-article-01.html
http://www.example.com/article/data-analysis.html
http://www.example.com/article/another-page.html

要重定向到:

http://www.example.com/article/some-article-01/
http://www.example.com/article/data-analysis/
http://www.example.com/article/another-page/

寻找一个适用于wordpress的htaccess规则...
指向相关数据的指针将被接受。似乎找不到合适的搜索查询。示例代码当然要容易得多。

1 个答案:

答案 0 :(得分:1)

DOCUMENT_ROOT/.htaccess文件中将此规则作为第一条规则插入RewriteBase行下方

RewriteEngine On
RewriteBase /

RewriteRule ^(article/[^.]+)\.html$ /$1/ [L,NC,R=302]

如果它适用于您,请将302更改为301以使其永久重定向。