从网址301重定向与查询字符串与不同的查询字符串的新域名 [英] 301 redirect from URL with query string to new domain with different query string

查看:190
本文介绍了从网址301重定向与查询字符串与不同的查询字符串的新域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何做301重定向在我的htaccess文件的一些文件重定向到一个新的领域。这就是我需要知道怎么做:

旧的URL: http://www.example.com/index ?PHP页面=新闻和ID = 2366

新的URL: http://www.example2.com/news.php?name = 23546

的重定向不必自动创建。我可以硬code,我需要在htaccess文件重定向页面,我只是不知道要使用的格式,因为我读过,标准的301重定向不会与查询字符串的工作。

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

 重定向301 /index.php?page=news&id=2366 http://www.example2.com/news.php?name=23546
 

解决方案

您可以使用一个重写规则与查询字符串匹配条件,如:

  RewriteEngine叙述上
的RewriteCond%{REQUEST_URI} ^ / index.php的$
的RewriteCond%{QUERY_STRING} ^页=新闻和ID = 2366 $
重写规则^(。*)$ http://www.example2.com/news.php?name=23546 [R = 301,L]
 

结帐这个博客页面关于它如何工作的更多信息。

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:

OLD URL: http://www.example.com/index.php?page=news&id=2366

NEW URL: http://www.example2.com/news.php?name=23546

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重定向与查询字符串与不同的查询字符串的新域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆