Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess重定向到单个子域_Apache_.htaccess_Redirect_Http Status Code 302 - Fatal编程技术网

Apache .htaccess重定向到单个子域

Apache .htaccess重定向到单个子域,apache,.htaccess,redirect,http-status-code-302,Apache,.htaccess,Redirect,Http Status Code 302,我有一个像www.example.com这样的网站,我想将每个点击重定向到这个URL和子URL,并将其重定向到子域上的单个URL。下面是一些例子 www.example.com应重定向到http://test.example.com www.example.com/show/mypage1应重定向到http://test.example.com www.example.com/show/mypage2应重定向到http://test.example.com www.example.com/sho

我有一个像
www.example.com
这样的网站,我想将每个点击重定向到这个URL和子URL,并将其重定向到子域上的单个URL。下面是一些例子

www.example.com
应重定向到
http://test.example.com

www.example.com/show/mypage1
应重定向到
http://test.example.com

www.example.com/show/mypage2
应重定向到
http://test.example.com

www.example.com/show/mypage3
应重定向到
http://test.example.com


我想用
.htaccess
来做这件事。我想要
302临时重定向
。我使用的是Apache Web服务器。

您使用的是Apache还是IIS

在Apache中:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://test.example.com/ [L,R=302]
编辑

已编辑:已替换
http://test.example.com/$1
http://test.example.com/
,它现在可以根据需要工作。


重新启动发动机
RewriteCond%{HTTP_HOST}^www\.example\.com$[NC]
重写规则^(.*)$http://test.example.com/ [L,R=302]

我正在使用Apache,您的代码将如何重定向到
http://test.example.com
我看不到任何对它的引用?@Ummar,不会的。该代码将去掉
www.
前缀,这是一个完全不同的问题的答案。如您所见,重写字符串使用正则表达式字符串,因此请求将转发给新的domain@TRiG,那么怎么做,请让我知道?您需要将mod_rewrite添加到您的Apache服务器配置中,在使用终端的新系统上,最常见的是:
sudoa2enmod rewrite
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://test.example.com/ [L,R=302]
</IfModule>