简体   繁体   English

使用htaccess将所有流量从根重定向到特定的子域页面

[英]Use htaccess to redirect all traffic from root to specific subdomain page

I have a site that has been up for some time. 我有一个网站已经有一段时间了。 I had a blog on a subdomain for some time. 有一段时间我在子域上有一个博客。 I have decided to do away with the main site and just support the blog subdomain. 我决定取消主网站,只支持博客子域名。

I have a redirect setup for this, but it carries all the extra parameters through to the blog which results in a file not found page appearing. 我有一个重定向设置,但它将所有额外的参数传递到博客,导致文件未找到页面出现。 I just want the redirect to go to the index page without parameters. 我只是希望重定向转到没有参数的索引页面。

What I currently have in my .htaccess file is this 我目前在.htaccess文件中拥有的是这个

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?(.*)$ "http\:\/\/blog\.foo\.org\/index\.php" [R=301,L]

When I get a request to 当我收到请求时

http://www.foo.org/foo/foo/?module=foo http://www.foo.org/foo/foo/?module=foo

it redirects to 它重定向到

http://blog.foo.org/foo/foo/index.php?module=foo http://blog.foo.org/foo/foo/index.php?module=foo

I want it to redirect to http://blog.foo.org/index.php 我希望它重定向到http://blog.foo.org/index.php

You have to specify the query in the replacement to override the original: 您必须在替换中指定查询以覆盖原始:

RewriteCond %{HTTP_HOST} !^blog\.example\.org$ [NC]
RewriteRule ^ http://blog.example.org/index.php? [R=301,L]
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.org$ [NC]
RewriteRule ^ http://blog.foo.org/ [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM