为了SEO目的,在实现URLS重写时,我得到了一个无限重定向循环。
示例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,而用户仍然可以看到原始URL。您已经将其设置为执行301重定向,因此用户访问的URL是/store_selection.php?store=id,即无限循环的原因。
为什么不使用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/