基于Apache的子域重写 [英] Apache rewrite based on subdomain
问题描述
我试着去重定向通配符域的子目录的请求。
IE浏览器。 something.blah.domain.com
- > blah.domain.com/something
我不知道怎么去子域名在重写规则使用。
最终解决方案:
的RewriteCond%{HTTP_HOST} ^!等等\\。域\\ .COM
的RewriteCond%{HTTP_HOST} ^([^。] +)
重写规则^(。*)/ 1%/ $ 1 [L]
或由pilif指出
的RewriteCond%{HTTP_HOST} ^([^。] +)\\。媒体\\ .xnet \\ $ .TK
您应该有一个看的 URL重写指南从Apache文档。
以下是未经测试,但它应该到的伎俩:
的RewriteCond%{HTTP_HOST} ^([^。] +)\\。等等\\。域\\ .COM $
重写规则^ /(。*)$ http://blah.domain.com/%1/$1 [L,R]
这只有在子域包含没有点工作。否则,你不得不改变的RewriteCond正则表达式匹配仍然应该由于工作锚固任何字符,但是这肯定感觉更安全。
Im trying to redirect requests for a wildcard domain to a sub-directory.
ie. something.blah.domain.com
--> blah.domain.com/something
I dont know how to get the subdomain name to use in the rewrite rule.
Final Solution:
RewriteCond %{HTTP_HOST} !^blah\.domain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)
RewriteRule ^(.*) /%1/$1 [L]
Or as pointed out by pilif
RewriteCond %{HTTP_HOST} ^([^.]+)\.media\.xnet\.tk$
You should have a look at the URL Rewriting Guide from the apache documentation.
The following is untested, but it should to the trick:
RewriteCond %{HTTP_HOST} ^([^.]+)\.blah\.domain\.com$
RewriteRule ^/(.*)$ http://blah.domain.com/%1/$1 [L,R]
This only works if the subdomain contains no dots. Otherwise, you'd have to alter the Regexp in RewriteCond to match any character which should still work due to the anchoring, but this certainly feels safer.
这篇关于基于Apache的子域重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!