我有一个现有域名的新网站。
我想将旧网址重定向到新网站,但简单的方法是: 重定向301 oldURL newURL 没有用。
有人告诉我,旧网址中包含index.php这个问题, 并且我需要一个重写规则......
新旧网址的示例:
old:http://www.example.com/index.php?type=store&category=11&subcategory=15&item=67
新:http://www.example.com/64-white-
非常感谢我需要插入HTACCESS
的规则提前
盖
答案 0 :(得分:2)
有几种方法可以在.htaccess中创建永久重定向:
RedirectPermanent /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
Redirect 301 /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
RedirectRule /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white- [L,R=301]
虽然,因为你在谈论从index.php重定向,我建议你考虑在代码中进行重定向。
例如,您可以创建一个oldsite_redirects.php文件,如下所示:
<?php
$redir_maps = array(
'/index.php?type=store&category=11&subcategory=15&item=67' => '/64-white-'
);
if(in_array(@$_SERVER['REQUEST_URI'], array_keys($redir_maps))){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redir_maps[@$_SERVER['REQUEST_URI']]);
exit;
}
?>
在index.php文件中添加以下行 ABOVE 所有代码和注释:
require_once('oldsite_redirects.php');
希望这会有所帮助。
答案 1 :(得分:0)
要在htaccess文件中进行永久重定向,可以使用RedirectPermanent:
RedirectPermanent /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
由于网址重写,我认为不可能使用正则表达式。