[英]How to rewrite subdomain and subsubdomain into a parameter?
Can anyone please help with the following rewrite for apache
? 任何人都可以帮助以下重写
apache
?
Imagine I have the domain domain.com
想象一下,我有域
domain.com
What I want: 我想要的是:
If people request www.domain.com then return www.domain.com (ie index.php in my root directory)
如果有人请求www.domain.com然后返回www.domain.com(即我的根目录中的index.php)
If people request subA.subB.domain.com then return www.domain.com?sub=subA.subB
如果有人请求subA.subB.domain.com,请返回www.domain.com?sub=subA.subB
If people request sub.domain.com then return www.domain.com?sub=sub
如果有人请求sub.domain.com,请返回www.domain.com?sub=sub
If people request domain.com then return www.domain.com
如果有人请求domain.com,请返回www.domain.com
I know the rule here is to work on it yourself. 我知道这里的规则就是自己动手。 I have.
我有。 For example, the similar question here asks to redirect to /subA/subB - but even if I understood that answer I would not know how to adapt it to what I need, which is ?sub=subA.subB .
例如,类似的问题在这里要求重定向到/ subA / subB - 但即使我理解了答案,我也不知道如何使它适应我需要的,这是?sub = subA.subB。 I have tried to understand rewrite many times over the years.
多年来,我试图多次理解重写。 Ok, /sobstory -off.
好的,/ sobstory -off。
This will rewrite your subdomains: 这将重写您的子域名:
RewriteEngine on
RewriteCond %{QUERY_STRING} !^sub=
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)\.domain\.com$
RewriteRule ^(/?)$ $1?sub=%1
Replace the domain as appropriate. 适当地替换域。 Make sure each
.
确保每一个
.
has a slash before it as it does now. 像现在一样在它之前有一个斜线。
It will only work for the index page. 它只适用于索引页面。 If you want it to work when there is something after
domain.com/
let me know. 如果你想在
domain.com/
之后有什么东西让它工作,请告诉我。
As for making http://domain.com
work, I suggest redirecting that to www.domain.com
so you don't get duplicate content issues from search engines. 至于使
http://domain.com
工作,我建议将其重定向到www.domain.com
这样你就不会从搜索引擎中获得重复的内容问题。 Do that with this (add it below the above): 这样做(在上面添加它):
RewriteCond %{HTTP_HOST} =domain.com
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,L]
No need for the slashes before the dots on that one. 不需要在那个点之前的斜线。
Let me know if any of that is no good for you. 如果有任何对你没有好处,请告诉我。
Original poster's postscript based on comments: 根据评论原创海报的后记:
The above solution is correct for the question but assumes the following configurations on the server: 上述解决方案对于该问题是正确的,但假设服务器上有以下配置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.