301从具有查询字符串的URL重定向到具有不同查询字符串的新域

She*_*ght 7 .htaccess redirect query-string http-status-code-301

我试图弄清楚如何在我的htaccess文件中执行301重定向以将一些文件重定向到新域.这是我需要知道如何做的:

旧网址:http://www.example.com/index.php? page = news&id = 2366

新网址:http://www.example2.com/news.php? name = 23546

重定向不必自动创建.我可以硬编码我需要在htaccess文件中重定向的页面,我只是不知道要使用的格式,因为我读过"标准"301重定向不适用于查询字符串.

基本上这就是我想做的事情,但到目前为止我的研究听起来并不像这样做.

redirect 301 /index.php?page=news&id=2366 http://www.example2.com/news.php?name=23546
Run Code Online (Sandbox Code Playgroud)

Reg*_*gie 19

您可以使用具有查询字符串匹配条件的重写规则,例如:

RewriteEngine On
RewriteCond   %{REQUEST_URI}    ^/index.php$
RewriteCond   %{QUERY_STRING}   ^page=news&id=2366$
RewriteRule   ^(.*)$ http://www.example2.com/news.php?name=23546   [R=301,L]
Run Code Online (Sandbox Code Playgroud)

查看此博客页面,了解有关其工作原理的更多信息.