子域名重定向 [英] Subdomain Redirect

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

问题描述

我希望写在.htaccess规则重定向

I want write a rule in .htaccess for redirecting

http://www.dir.domain.com
http://dir.domain.com
http://www.domain.com/dir

这些应该重定向到

http://domain.com/dir

在此先感谢...

Thanks in advance...

推荐答案

这里的技巧是使用的.htaccess 文件在您DOCROOT

The trick here is to use an .htaccess file in your DOCROOT

RewriteEngine on
RewriteBase   /

RewriteCond   %{HTTP_HOST}    ^(www\.)?dir\.domain\.com$
RewriteRule   ^.*             http://domain.com/dir/$0     [R=301,L]

RewriteCond   %{HTTP_HOST}    ^www\.domain\.com$
RewriteRule   ^dir/.*         http://domain.com/$0         [R=301,L]

请注意,这是在做301重定向 - 这是服务器告诉浏览器,这是一个永久重定向和浏览器缓存此重定向

Note that this is doing a 301 redirect -- that is the server tells the browser that this is a permanent redirect and the browser caches this redirect.

您也可以做一个内部重定向,其中该映射默默的在服务器端通过调整标志完成。

You can also do an internal redirect where this mapping is done silently at the server end by tweaking flags.

这假定您的共享服务使用Apache的,如果使用IIS,那么你需要做的web.config中类似的事情

This assumes that your shared service is using Apache, if its using IIS, then you need to do something similar with the web.config

这篇关于子域名重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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