指着用的.htaccess一个子域到子文件夹 [英] Pointing a subdomain to a subfolder using .htaccess

查看:231
本文介绍了指着用的.htaccess一个子域到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的虚拟主机提供商自动转发所有的请求* .mydomain.com到顶层域mydomain.com。

My webhost automatically forwards all requests to *.mydomain.com to the toplevel domain mydomain.com.

我想映射任何子域到一个特定的文件夹在我的顶级域名。即sub.example.com必须映射到example.com/someFolder(没有在地址栏的变化)。

I wanted to map any subdomain to a specific folder on my toplevel domain. i.e. sub.example.com must be mapped to example.com/someFolder (without change in the address bar).

在网络上周围挖后,我想出了这一点:

After digging around on the net, I came up with this:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) http://example.com/myfolder/$1 [L]

这似乎运作良好,但有一个问题:当我去到URL sub.example.com,在地址栏上的网址example.com/myfolder~~V。但是,当我做这样的事情sub.example.com/login - 这映射到example.com/sub/login~~V不正确的地址栏中的变化。任何帮助非常AP preciated!

This seems to work well, except for one problem: When I go to the URL sub.example.com, the URL in the address bar changes to example.com/myfolder . But, when I do something like sub.example.com/login - this maps to "example.com/sub/login" properly without the change in the address bar. Any help greatly appreciated!

推荐答案

只需要小的变化:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) myfolder/$1 [L]

剥离出来的http://在此告诉Apache发送一个重定向头,而不是正确的服务器端重写规则

stripped out http:// at the rule which tells Apache to send a Redirect header instead of proper server-side rewrite.

这篇关于指着用的.htaccess一个子域到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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