.htaccess 301重定向到新的URL结构

时间:2012-03-06 09:33:24

标签: php apache .htaccess http-status-code-301

我有以下网址结构,我需要301一个新的URL结构。

旧结构  /bla-bla-bla-400252596261.html

新结构  /listing/bla-bla-bla-400252596261.html

如何在.htacces中完成此操作?

编辑:我在root上有其他文件,但不是以.html结尾,所以它应匹配该字符串。因此,根目录中与.html扩展名匹配的任何文件都应重定向到/listing/bla-bla-bla-400252596261.html页面。

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteCond %{REQUEST_URI} ^/.*\.html$
RewriteCond %{REQUEST_URI} !^/listing.*
RewriteRule ^(.*\.html)$ /listing/$1 [R=301,QSA,L]

更多示例here

相关问题