无限重定向循环 - 重写URL
实现重写URL目标时,我得到无限重定向循环。无限重定向循环 - 重写URL
示例URL
`<a><?php echo make_store_name_url($store_id); ?><?php echo $store_name; ?></a>`
我有一个函数来重写动态URL - 下面是一个例子
function make_store_name_url($store_id)
{
//build the keyword rich url
$url = SITE_URL . '/store/' . $store_id .'/';
//return the URL
return $url;
}
//function to redirect using 301
function fix_store_name_url()
{
$proper_url = get_proper_store_name_url();
if(SITE_URL . $_SERVER['REQUEST_URI'] != $proper_url)
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $proper_url);
exit();
}
}
function get_proper_store_name_url()
{
$store_id = $_GET["store"];
$proper_url = make_store_name_url($store_id);
return $proper_url;
}
最后我在htaccess的线重写。请注意,当不使用重定向时,重写工作正常。
RewriteRule ^store/([0-9]+)/$ /store_selection.php?store=$1 [R=301,L]
不知道我的无限重定向循环出了什么问题。任何帮助,将不胜感激。
你的.htaccess更改为:
RewriteRule ^store/([0-9]+)/$ /store_selection.php?store=$1 [QSA,L]
这只是内部重写URL,而用户仍显示原来的。您已将其设置为301重定向,因此用户正在点击的URL是/store_selection.php?store=id,即无限循环的原因。
我仍然得到重定向循环。我已经使用fiddler检查了标题,并且重写的URL的位置正确,但是我仍然得到21 301重定向。 @Birla – user2058618 2013-02-10 21:05:18
@ user2058618它对我来说非常完美。但是,如果我将'QSA'改回到'R = 301',它会陷入无限循环。浏览器中可能存在缓存问题。 – Birla 2013-02-11 04:10:48
为什么不用RewriteLog调试重写规则?
# Roll your own Rewrite log
# Log details via scale of 1 to 9
# 1 = few details, 5 = enough details, 9 = too much detail
RewriteEngine On
RewriteLog "/your/path/rewrite.log"
RewriteLogLevel 5
http://perishablepress.com/roll-your-own-apache-rewrite-log/
当我尝试在htaccess中执行此操作时,出现500错误。 – user2058618 2013-02-10 21:46:47
后'$ proper_url = get_proper_store_name_url();'插入这条线,看看2页的URL是否实际上类似。 'echo SITE_URL。 $ _SERVER ['REQUEST_URI']。 '='。 $ proper_url;退出;' – blackpla9ue 2013-02-11 07:57:57
我做了上述,他们是相似的,所以我假设有一个问题,我的重写。 @ blackpla9ue – user2058618 2013-02-11 08:34:05
如果你不介意你能不能粘贴从我给的代码打印的输出? – blackpla9ue 2013-02-11 08:43:51