Home redirect all requests to subdomain to an appropriate folder
Reply: 1

redirect all requests to subdomain to an appropriate folder

Autolycus
1#
Autolycus Published in 2018-02-12 22:57:00Z

I have multiple clients that I have subdomains for client1.example.com client2.example.com ... etc etc

now in my root directory I have one common code base and rest is different depending on clients

so in my root directory I have these folders mymainrepo client1 client2

mymainrepo contains all the common code

client1 contains multiple folders like cache dbsettings client2 contains multiple folders like cache dbsettings

But the content of cache and dbsettings is different for every client. so what I want to do is if a request comes in for a client and it asks for a cache folder contenet, i want it to be served form that clients folder

so if a request is client1.example.com/cache it will serve the contents from

doc root
    |
    |
     -------client1
                |
                |_______cache

and if the request is client2.example.com/cache it will serve from

doc root
        |
        |
         -------client2
                    |
                    |_______cache

and so on and so on.

Any help will be appreciated thanks

** EDITED **

ok so I tried this and this sorta works

RewriteEngine on
RewriteCond %{HTTP_HOST} ^((?!www\.).+)\.domain.com$[nc]
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [r=301,nc]
DirectoryIndex client1/index.html

problem is I want to have this dynamic instead of client1 hard coded

DirectoryIndex client1/index.html

I tried

DirectoryIndex %1/index.html

but that did not work

any help will be appreciated

starkeen
2#
starkeen Reply to 2018-02-13 03:24:22Z

You can use something like the following

RewriteEngine on


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

This will rewrite client.domain.com/path to the /client folder of your main document root. So if the request is client.domain.com/cache this will internally redirect it to /client/cache showing you the contents from that folder.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318243 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO