Link to an old page that already has a permanent redirect

I have a 301 redirect of the oldPage.php form to newPage.php in htaccess:

RedirectMatch 301 ^/oldPage.php$ /newPage.php

      

Now I would like forceOldPage.php to redirect to oldPage.php (without redirecting to newPage.php)

Is it possible? How can i do this?

+3


source to share


2 answers


First remove the redirect .htaccess

and redirect to oldPage.php

if the referent is not forceOldPage.php

.

Something like this at the top oldPage.php

is a good start, tweaked and refined as needed.



<?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();
}

?>

      

+2


source


One possibility is to assume that "force" (select any row) will not be part of the query string on any page going to oldPage.php. Use RewriteCond and RewriteRule. Then reassign forceOldPage.php to oldPage.php? Force.

RewriteEngine on
RewriteCond %{QUERY_STRING} !force
RewriteRule oldPage.php newPage.php [R=301]
RedirectMatch 301 ^/forceOldPage.php$ /oldPage.php?force

      



FYI: I tried using HTTP_REFERER as a way to detect if a user came from forceOldPage. However, the referent is not passed to the new page on redirection (at least in my environment).

0


source







All Articles