Htaccess subdomain verification

I need help with the htaccess subdomain to point to a specific file in a folder.

Separate php files must be contained inside the parent folder in order to properly scroll the correct applications. Sounds simple.

The url the user has a type should not be modified / redirected, instead it should "link" to the correct file in the background

An example when a custom type userbase.company.com

should point to

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

      

Likewise, when a custom type userbase2.company.com

should point to

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

      

but the redirection shouldn't happen. URL links must remain on

http://userbase2.company.com 

      

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

I currently 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]

      

Am I going to put this on /public_folder/

right? Not on /public_folder/userbase

?

+2


source to share


1 answer


This rule should do the following 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]

      

  • The url will remain unchanged in the browser (means rewrite - internal redirect).

  • It only works for something.domain.com

    (not domain.com

    or www.domain.com

    ).

  • He will rewrite this request http://user1.company.com/hello/pink/kitten.php

    in/parent/user1.php/hello/pink/kitten.php

  • If the subdomain is complex (for example www.something.domain.com

    ), it will also be reflected in the rewrite: for example, it http://www.something.company.com/hello/pink/kitten.php

    will be rewritten to /parent/www.something.php/hello/pink/kitten.php

    . If this behavior is undesirable (I don't know your requirements 100%), you need to add 1 more condition to the rule.

  • The home page request (for example http://user1.company.com/

    ) will be rewritten like this:/parent/user1.php/



PS The rule was checked before posting - works great, but you need to check and possibly tweak it if it should work with your CodeIgniter application (sorry, I'm not familiar with this framework).

In any case, this rule should be higher for CodeIgniter rewrite rules (if any).

+3


source







All Articles