Mobile app version of vmapp.org
Login or Join
Mendez628

: Apache / cPanel document root for subdirectory In cPanel, I'm aware how to set document roots for domains, but I'm trying to have different document roots for a domain depending on the subdirectory.

@Mendez628

Posted in: #AddOnDomain #Apache #Cpanel #Htaccess

In cPanel, I'm aware how to set document roots for domains, but I'm trying to have different document roots for a domain depending on the subdirectory.


URL | Document Root
example.com | home/public_html/splash
example.com/foo | home/public_html/apples
example.com/bar | home/public_html/oranges
foo.com | home/public_html/splash
foo.com/foo | home/public_html/apples
foo.com/bar | home/public_html/oranges


As you can see, there may be multiple domains that use the same subdirectory => document root scheme.

Any recommendations?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Mendez628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Annie201

There are many ways.

An easy way is via apache's mod_rewrite. For your example, you can use rules and files as follows:

Make an .htaccess file in /home/public_html/splash with the following contents:

RewriteEngine On
RewriteRule ^foo(.*)$ /apples [L]
RewriteRule ^bar(.*)$ /oranges [L]


That will work nicely for example.com and if you point foo.com to the same folder, then you're set.

Another way is to go in the linux shell and create symbolic links named foo and bar inside the splash folder (using the ln command) and make it point to /apples and /oranges respectively.

And for a cheap way out, you can create the folders named foo and bar inside public_html and create index files (index.html or index.php for example) and script it so it redirects to the correct folder, but that option depending on what you're doing might not fit your needs.

So the best case here is the first option. Use apache's mod_rewrite to map tails of URL's to folders just like I have done.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme