Change the document root of a parked domain?

7.4k Views Asked by At

I have run into a problem which is that my web host doesn't appear offer addon domains.

I currently have a domain name pointing to my name servers.

I went into cPanel to add an addon domain that points to a sub-directory, but all that is available in cPanel is to park domain at the document root which is 'public_html/'.

So traffic coming from the parked domain would get the wrong content, which is obviously not good.

I get the feeling that this isn't possible, but can I change the parked domain document root from 'public_html/' to 'public_html/sub-directory' ?

Or perhaps can I edit the .htaccess file to redirect traffic from the parked domain to the sub-directory?

Basically I want this address; www.parked-domain.com/

To show the content of this sub-directory; www.first-domain.com/parked-directory

I hope this is possible otherwise I need to look at a new web host.

Regards,

Dean.

3

There are 3 best solutions below

2
On

Add the following to your .htaccess file:

RewriteRule ^parked-directory - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com$ [NC]
RewriteRule ^(.*)$ parked-directory/$1 [L]
1
On

instead of using "parked domain", use the addon domain - and here just the root directory to public_html/sub-directory where you want to point your new "parked" domain...

2
On

While frowned upon, it is possible to dynamically set up your parked domain sub-hosts using mod_rewrite.

Here's a .htaccess sample for multihosting via mod_rewrite using a dynamic format that requires parked-domain-name = sub-folder-name, and covers other parked domains on your site being redirected or ignored.

# tell mod_rewrite to activate and give base for relative paths
  RewriteEngine on
  RewriteBase   /

# permanent redirect of unused parked domains so they do not try to resolve.
# only use this redirect if you want multiple names to point to another.
# otherwise, replace the rewrite rule with: RewriteRule . - [F,L]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain1\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain2\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain3\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain4\.com$ [NC]
  RewriteRule ^(.*)$         http://main-site.com/$1 [L,R=301]

# if you have an active site in hosting root folder,
# then tell it not to look for a subfolder by skipping next rule
  RewriteCond %{HTTP_HOST}   ^(www\.)?main-site\.com [NC]
  RewriteRule ^(.*)$         - [S=1]

# the domain-name = sub-folder automation
# thus parked-domain5.com in /parked-domain5/
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com
  RewriteCond %{REQUEST_URI} !^/%1
  RewriteRule ^(.*)$         %1/$1 [L]

# if you're hosting wordpress sites, this is a tweaked variant of the WP code.
# add the rest of this example only if:
#   1. main-site.com is a WP site
#   2. you remove .htaccess in subfolders
# if (1.) true, yet keeping subfolder .htaccess, uncomment next 2 lines:
# RewriteCond %{HTTP_HOST} !^(www\.)?main-site\.com [NC]
# RewriteRule ^(.*)$ - [S=1]
#### BEGIN WordPress, improved
# if this request is for "/" or has already been rewritten to WP 
  RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file 
  RewriteCond $1 \.(gif|jpg|jpeg|png|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file 
  RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory 
  RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP 
  RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP 
  RewriteRule . /index.php [L]
# END WordPress