htaccess subdomain pointing

≯℡__Kan透↙ 提交于 2019-12-02 00:20:11

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!