首页 > 解决方案 > .htaccess 301 路径 URL 重组?

问题描述

我阅读了很多关于完整域的 301 重定向的内容,但无法了解如何将现有路径准确更改为新路径。

这是一个例子:

site.com/carssite.com/motobikes

和:

site.com/cars/tiressote.com/motobikes/(变量,例如柏林、巴黎)/tires

我怎样才能完成这项任务?

标签: phpregexapache.htaccess

解决方案


您可以在 PHP 中以这种方式进行重定向

header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.example.com/$var"); 
    exit();

或者您可以使用 .htaccess 文件Redirect 301 /cars http://example.com/motobikes


推荐阅读