htaccess的重定向到具有路径和参数的新领域 [英] htaccess redirect to new domain with path and parameters

查看:181
本文介绍了htaccess的重定向到具有路径和参数的新领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重定向所有流量的一个文件夹到一个新的领域。设置如下:

I need to redirect all traffic for one folder to a new domain. The setup is as follows:


  • 原网站有一个文件夹管理与.htaccess文件(见下面我重写规则)

  • 所有流量应该去另一个网站

  • 路径和参数应该是preserved

我做了以下重写规则:

RewriteEngine on
RewriteRule     (.*)      http://admin.testsite.com/admin/$1 [R=301,L]

这适用于参数,但不适合的路径。以下URL不会重定向:

This works for parameters, but not for the path. The following url won't redirect:

www.oldsite.com/admin/account/?test=3

我怎样才能得到这个URL重定向到 admin.testsite.com/admin/account/?test=3

注意:在根有另一个htaccess的以下规则:

NB: In the root there is another .htaccess with the following rules:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /users/index\.php\?file=(.+)&group=(.+)\ HTTP/
RewriteRule ^users/index\.php$ /users/%1/%2\.html? [L,R=301]

可这影响到其他规则?

Can this affect the other rule?

推荐答案

下面是官方的回答。

问题是:如何才能www.oldsite.com/admin/account/?test=3到redirec到admin.testsite.com/admin/account/?test=3~~V?

Question was: "How can get www.oldsite.com/admin/account/?test=3 to redirec to admin.testsite.com/admin/account/?test=3?"

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^/admin/(.*)$  http://admin.testsite.com/admin/$1 [R=301,L]            
</IfModule>

这篇关于htaccess的重定向到具有路径和参数的新领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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