htaccess的子域沉默重定向 [英] htaccess subdomain silent redirect
问题描述
予有子域的每个用户,user1.domain.com成功地指向domain.com/user1~~V
I have subdomains for each user, user1.domain.com that successfully points to domain.com/user1.
我的问题是我怎么办呢,这样 http://user1.domain.com/admin做了SILENT重定向到 http://domain.com/admin ?
My question is how do I do it so that http://user1.domain.com/admin does a SILENT redirect to http://domain.com/admin?
我想将此应用到所有子目录中的子域,因此user1.domain.com/cart沉默重定向到domain.com/cart~~V&安培; user1.domain.com/cart/checkout/confirmation - > domain.com/cart/checkout/confirmation等等,等等。请记住,这个目录实际上并不在子域存在,只有根域。
I want to apply this to all subdirectories in the subdomain, so user1.domain.com/cart silent redirects to domain.com/cart & user1.domain.com/cart/checkout/confirmation -> domain.com/cart/checkout/confirmation so on and so forth. Bear in mind that this directories don't actually exist in the subdomains, only the root domain.
我已经试过搜索#1,但无法找到一个答案,我的具体问题。谢谢!
I've tried searching Stackoverflow but could not find an answer to my specific issue. Thanks!
推荐答案
这不是一个重定向,除非浏览器知道这件事,有没有这样的东西作为一个沉默重定向。你有两个选择,你可以代表浏览器中的任何代理,也可以在内部重写请求如果这两个 user1.domain.com
和 domain.com
共享同一个文档根目录
It's not a redirect unless the browser knows about it, there's no such thing as a "silent" redirect. You have 2 options, you can either proxy on behalf of the browser, or you can internally rewrite the request if both user1.domain.com
and domain.com
share the same document root.
要代理:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/%1/$1 [L,P]
在 P
标志指示代理。这条规则的不会的工作,除非你有mod_proxy的加载。如果所有的域指向同一个文档根目录,那么你可以简单地改写:
The P
flag indicates a proxy. This rule will not work unless you have mod_proxy loaded. If all your domains point to the same document root, then you can simply rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
这篇关于htaccess的子域沉默重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!