我在 htaccess 中有一个从 oldPage.php 到 newPage.php 的 301 重定向:
RedirectMatch 301 ^/oldPage.php$ /newPage.php
现在我想将 forceOldPage.php 重定向到 oldPage.php(而不是重定向到 newPage.php)
这可能吗?我该怎么做?
最佳答案
首先删除您的 .htaccess
重定向,如果引用者不是 forceOldPage.php
,则改为在 oldPage.php
中重定向。
oldPage.php
顶部的类似内容是一个好的开始,请根据需要进行调整和完善。
<?php
// If the referring page isn't "forceOldPage.php"...
if ( !strpos( $_SERVER['HTTP_REFERER'], 'forceOldPage.php' ) ) {
// ...301 redirect to "newPage.php"
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: /newPage.php" );
die();
}
?>
关于php - 链接到已经具有永久重定向的旧页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27414966/