使用htaccess将所有.html文件重定向到旧网站


Redirect all the .html files to old site with htaccess

我想将所有以.html结尾的文件重定向到旧站点文件夹,目前我的htaccess如下所示:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # RedirectMatch 302 /(.+?).html$ http://superawesomedomain.com/old/$1.html [L] RewriteRule ^index'.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

但根据我的条件RedirectMatch 302,当我申请时http://superawesomedomain.com/old/old/old/old/old/old...old/old/old...old/old/old/直到它破坏浏览器:(

关于如何进行重定向,有什么想法吗?

谢谢!

您可以使用以下规则:

RewriteEngine On
RewriteBase /
RewriteRule ^((?!old/).+?'.html)$ /old/$1 [L,NC,R=302]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
  • 不要将RedirectMatch与其他mod_rewrite规则一起使用
  • 当URI已经以/old/开始以停止重定向循环时,请确保您没有重定向