【发布时间】:2018-09-25 20:06:59
【问题描述】:
我阅读了很多关于完整域的 301 重定向的内容,但不知道如何准确地将现有路径更改为新路径。
这是一个例子:
site.com/cars 到 site.com/motobikes
还有:
site.com/cars/tires 到 sote.com/motobikes/(变量,例如柏林、巴黎)/tires
我怎样才能完成这项任务?
【问题讨论】:
标签: php regex apache .htaccess
我阅读了很多关于完整域的 301 重定向的内容,但不知道如何准确地将现有路径更改为新路径。
这是一个例子:
site.com/cars 到 site.com/motobikes
还有:
site.com/cars/tires 到 sote.com/motobikes/(变量,例如柏林、巴黎)/tires
我怎样才能完成这项任务?
【问题讨论】:
标签: php regex apache .htaccess
试试这个:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^cars http://example.com/motorbikes [R=301,L]
还有:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^cars/tires http://example.com/motobikes/berlin/tires [R=301,L]
【讨论】:
您可以在 PHP 中像这样进行重定向
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/$var");
exit();
或者您可以使用 .htaccess 文件Redirect 301 /cars http://example.com/motobikes
【讨论】: