Apache 301 重定向除一个文件之外的所有文件

Apache 301 重定向除一个文件之外的所有文件

我目前正在返回旧域名并创建重定向以用于 SEO。我还没有做过太多这样的事,所以我在学习过程中不断进步。

我试图:

  • 将一些页面直接 301 到新网站上的等效页面(已完成)
  • 有一个页面根本没有重定向(需要帮助)
  • 将所有其他页面重定向到新主页(完成)

到目前为止我已经:

RedirectMatch 301 contactinfo.html http://www.newdomain.com/contact.php
RedirectMatch 301 (.).html http://www.newdomain.com/index.php 

我如何才能禁止单个页面的重定向?

答案1

这些Redirect指令实际上没有灵活性来实现这一点。尝试使用 mod_rewrite:

RewriteEngine on
# Equivalent to your first RedirectMatch
RewriteRule ^contactinfo\.html$ http://www.newdomain.com/contact.php [R=301,L]
# Avoids taking any action on this page.
RewriteRule ^filetonotredirect\.html$ - [L]
# Equivalent to your second RedirectMatch
RewriteRule ^.*\.html$ http://www.newdomain.com/index.php [R=301,L]

相关内容