1

我有个问题。Сustomer 更改了他网站上的永久链接,并要求我将 301 重定向设置为旧的永久链接。

旧版本:http ://my-site.by/catalog/?branch=3855

新版本: http: //my-site.by/catalog/3855/

我尝试了不同的方式,但它不起作用......有人可以帮助我吗?

UPD

哦对不起。差点忘了说。我已经厌倦了在 PHP 端进行这项工作 :)

我的解决方案:

if (strpos($_SERVER['REQUEST_URI'], '/catalog/?branch=') !== false)
{
  header(«HTTP/1.1 301 Moved Permanently»);
  header(«Location: www.my-site.by/catalog/».str_replace("/catalog/?branch=","",$_SERVER['REQUEST_URI'])."/");
  exit();
}

可能需要其他人。

4

1 回答 1

0

将此添加到您的 htaccess :

# 301 Redirect - url to url
    RewriteRule http://my-site.by/catalog/?branch=3855  http://my-site.by/catalog/3855/ [R=301,L,NC]

如果您想对所有此类 url 执行此操作:

# 301 Redirect - Dynamic Rewriting
RewriteRule ^catalog/?branch=([0-9]+)$ catalog/$1/
于 2012-07-27T15:18:44.517 回答