Php 链接到已具有永久重定向的旧页面
我在htaccess中有一个301重定向表单oldPage.php到newPage.php:Php 链接到已具有永久重定向的旧页面,php,.htaccess,url,Php,.htaccess,Url,我在htaccess中有一个301重定向表单oldPage.php到newPage.php: RedirectMatch 301 ^/oldPage.php$ /newPage.php 现在我想将forceOldPage.php重定向到oldPage.php(而不重定向到newPage.php) 可能吗?我该怎么做?首先删除您的.htaccess重定向,如果引用者不是forceOldPage.php,则改为在oldPage.php中重定向 在oldPage.php顶部的类似内容是一个很好的开始
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();
}
?>
一种可能性是假设“force”(选择任意字符串)不会成为任何页面上转到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不会在重定向时传递到新页面(至少在我的环境中)