2014-12-11 139 views
3

我有一個301重定向形式oldPage.php到newPage.php htaccess的:鏈接到舊的一頁已經有永久重定向

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

現在我想forceOldPage.php重定向到oldPage.php(沒有被重定向到newPage.php)

可能嗎?我怎樣才能做到這一點?

回答

2

首先刪除您的.htaccess重定向,而改爲oldPage.php如果referer不是forceOldPage.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(); 
} 

?> 
0

一種可能性是假設「強制」(選擇任何字符串)將不會成爲去往oldPage.php的任何頁面的查詢字符串的一部分。使用RewriteCond和RewriteRule。然後將forceOldPage.php重定向到oldPage.php?force。

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

僅供參考:我嘗試使用HTTP_REFERER作爲檢測用戶是否來自forceOldPage的方法。但是,referer不會傳遞到重定向的新頁面(至少在我的環境中)。