htaccess的子域名指向 [英] htaccess subdomain pointing

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

问题描述

我需要htaccess的子域一些帮助将指向特定的文件的文件夹。

在父文件夹应包含个人PHP文件正确路径合适的应用程序。听起来很简单这里。

用户的类型不应该改变/重定向的URL,而不是只宜 在后台链接到正确的文件

例如,当用户键入 userbase.company.com 应指向

  http://company.com/parent/userbase.php
 

同样,当用户键入 userbase2.company.com 应指向

  http://company.com/parent/userbase2.php
 

但没有重定向应该发生。 URL链接应保持在

  http://userbase2.company.com
 

夹将是相同的,但不是该文件。这可能吗?

目前我有这样的htaccess code:

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ userbase.company.com $ [OR]
的RewriteCond%{HTTP_HOST} ^ www.userbase.company.com $
重写规则^(。*)$ \ ./父/ userbase.php / $ 1 [L]
 

我将不得不把这个在 / public_folder / 吗?而不是在 / public_folder /用户群

解决方案

这个规则应该做的工作:

  RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{REQUEST_URI}!^ /父母/
的RewriteCond%{HTTP_HOST}!= domain.com
的RewriteCond%{HTTP_HOST}!= www.domain.com
的RewriteCond%{HTTP_HOST} ^([^ \。] +)\。域\ .COM $
重写规则(。*)/parent/%1.php%{REQUEST_URI} [L]
 

  1. URL将在浏览器中保持不变(手段改写 - 内部重定向)。

  2. 这将只适用 something.domain.com (而不是 domain.com www.domain.com )。

  3. 这将改写这一要求 http://user1.company.com/hello/pink/kitten.php /母/user1.php/hello/pink/kitten.php

  4. 如果子域是复杂的(如 www.something.domain.com ),那么它会反映在重写,以及:如 http://www.something.company.com/hello/pink/kitten.php 将被改写为 /parent/www.something.php /hello/pink/kitten.php 。如果这样的行为是不希望(我不知道你的要求,100%),那么你就需要增加1多个条件的规则。

  5. 请给一个主页(例如: http://user1.company.com/ )将被以这种方式重写: /parent/user1.php /

P.S。 规则在发布前进行测试 - 工作得很好,但你必须检查并可能调整它,如果它需要你的codeIgniter应用工作(对不起,我不熟悉的框架)

在任何情况下,这个规则应该是上面您codeIgniter重写规则(如果有这样的)。

I need some help on the htaccess subdomain to be pointed to specific file in a folder.

Inside the parent folder should contain individual php files to correctly path the right applications. Sounds simple here.

The url that the user has type should not change / redirect, instead it should only "link" to the correct file at the background

Example when user type userbase.company.com it should point to

http://company.com/parent/userbase.php

Similarly, when user type userbase2.company.com it should point to

http://company.com/parent/userbase2.php

but no redirection should happen. url links should remain at

http://userbase2.company.com 

folder would be the same, but not the file. Is it possible?

Currently I have this htaccess code:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^userbase.company.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.userbase.company.com$
RewriteRule ^(.*)$ \./parent/userbase.php/$1 [L]

I'm going have to put this at /public_folder/ right? Not at the /public_folder/userbase ?

解决方案

This rule should do the job:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/parent/ 
RewriteCond %{HTTP_HOST} !=domain.com
RewriteCond %{HTTP_HOST} !=www.domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$
RewriteRule (.*) /parent/%1.php%{REQUEST_URI} [L]

  1. URL will remain unchanged in browser (means rewrite -- internal redirect).

  2. It will only work for something.domain.com (not domain.com or www.domain.com).

  3. It will rewrite this request http://user1.company.com/hello/pink/kitten.php into /parent/user1.php/hello/pink/kitten.php

  4. If subdomain is complex (e.g. www.something.domain.com) then it will be reflected in rewrite as well: e.g. http://www.something.company.com/hello/pink/kitten.php will be rewritten to /parent/www.something.php/hello/pink/kitten.php. If such behaviour is undesired (I do not know your requirements for 100%) then you will need add 1 more condition to the rule.

  5. Request for a home page (e.g. http://user1.company.com/) will be rewritten in this way: /parent/user1.php/

P.S. Rule was tested before posting -- works fine, but you have to check and maybe tweak it if it needs to be working with your CodeIgniter app (sorry, I'm not familiar with that framework).

In any case this rule should be above your CodeIgniter rewrite rules (if there are such).

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

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