php - 链接到已经具有永久重定向的旧页面

标签 php .htaccess url

我在 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/

相关文章:

php - 如何在 Laravel 中选择外键值

php - Ruby 相当于 php_sapi_name

php - Symfony2 : Check if JSON value is in response and if it's TRUE in test

php - .htaccess 不重定向到 404.php 而是显示页面名称

php - htaccess 阻止访问除 style.php 文件之外的 php 文件

python - 如何从 url 在 Google Lens 窗口中进行搜索?

php - 使用数组值更新 MySQL 数据库

javascript - 删除 index.php WAMP

URL 的 Java Android 重定向不起作用

ios - 从暂停状态 iOS 恢复 safari