子域名指向的子文件夹(无重定向) [英] Subdomain point to subfolder (WITHOUT REDIRECT)

查看:80
本文介绍了子域名指向的子文件夹(无重定向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE了一整天,我不能得到这个权利。我有以下的规则,在我的htaccess文件:

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^(。*)\。域\ .COM $
的RewriteCond%{HTTP_HOST}!^应用\。域\ .COM $ [NC]
重写规则^(。*)$ http://app.domain.com/site/%1/$1 [L]
 

这是什么code的作用是如下

请访问: subsite.domain.com/contact-us 它会将您重定向到的 app.domain.com/site/subsite/contact-us

这就是我想要的,但我不希望有一个实际的重定向。所以,当我浏览这个子站点我一直想有 subsite.domain.com / [什么...]

我已阅读,从重写规则中删除域名将修复它。但它不工作...

这是可能的,只需htaccess的规则?

解决方案
  

因此​​,唯一的解决方案,这对增加新entires在每个子域   虚拟主机文件?

这是不完全准确。

您可以创建通配符子域,使任何子域名会被接受。 在DNS中为您的域名添加子域名名为 *

  *。example.com 192.168.1.1
 

然后在下面服务器名称你的apache的虚拟主机文件添加一个新的 serveralias 行或将其添加到现有的 serveralias

  ServerAlias​​ * .domain.com
 

然后在你的.htaccess文件中尝试使用代理使用标志P ,因为你不能重写使用不同的域名或它会做一个重定向,你已经找到了。确保的mod_proxy 在Apache的启用。它通常是。那么你的应用程序可以处理请求的文件夹。

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^(。+)\。域\ .COM $
的RewriteCond%{HTTP_HOST}!^应用\。域\ .COM $ [NC]
重写规则^(。*)$ http://app.domain.com/site/%1/$1 [P]
 

I have googled all day long and I cant get this right. I have the following rule in my htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteCond %{HTTP_HOST} !^app\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://app.domain.com/site/%1/$1 [L]

What this code does is as following

Visit: subsite.domain.com/contact-us It will redirect you to app.domain.com/site/subsite/contact-us

This is what I want BUT i dont want an actual redirect. So when I browse this "subsite" I always wanna have subsite.domain.com/[something...]

I have read that removing the domain name from the RewriteRule will fix it. But it doesnt work...

Is this possible with just htaccess rules?

解决方案

So the only solution to this to add new entires for each subdomain in the vhost file?

That's not entirely accurate.

You can create wildcard subdomains so that any subdomain will be accepted. In DNS for your domain name add a subdomain called *.

*.example.com 192.168.1.1

Then in your apache vhost file below ServerName add a new serveralias line or add it to the existing serveralias.

ServerAlias *.domain.com

Then in your .htaccess file try using a proxy using the P flag because your can't use a different domain name in rewrite or it will do a redirect as you have found out. Ensure mod_proxy is enabled in apache. It usually is. Then your app can handle the requested folders.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$
RewriteCond %{HTTP_HOST} !^app\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://app.domain.com/site/%1/$1 [P]

这篇关于子域名指向的子文件夹(无重定向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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