基于Apache的子域重写 [英] Apache rewrite based on subdomain

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

问题描述

我试着去重定向通配符域的子目录的请求。

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屋!

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