301 从带有查询字符串的 URL 重定向到带有不同查询字符串的新域 [英] 301 redirect from URL with query string to new domain with different query string
问题描述
我想弄清楚如何在我的 htaccess 文件中进行 301 重定向以将一些文件重定向到新域.以下是我需要知道的操作:
I am trying to figure out how to do a 301 redirect in my htaccess file to redirect some files to a new domain. Here's what I need to know how to do:
旧网址:http://www.example.com/index.php?page=news&id=2366
新网址:http://www.example2.com/news.php?name=23546
重定向不必自动创建.我可以在 htaccess 文件中对需要重定向的页面进行硬编码,我只是不知道要使用的格式,因为我读过标准"301 重定向不适用于查询字符串.
The redirects don't have to be automatically created. I can hard-code the pages I need to redirect in the htaccess file, I just don't know the format to use as I've read that a "standard" 301 redirect won't work with query strings.
基本上这就是我想要做的,但从我目前的研究来看,这听起来似乎不能这样做.
Basically this is what I want to do, but from my research so far it doesn't sound like it can be done this way.
redirect 301 /index.php?page=news&id=2366 http://www.example2.com/news.php?name=23546
推荐答案
您可以使用带有查询字符串匹配条件的重写规则,例如:
You could use a rewrite rule with a query string match condition, such as:
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]
查看此博客页面,了解有关其工作原理的更多信息.
Checkout this blog page for more information on how this works.
这篇关于301 从带有查询字符串的 URL 重定向到带有不同查询字符串的新域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!