Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a hosting account with godaddy. Its a linux system running apache. The way they do their setup is your primary domain is the root folder. When you add a subdomain its in a subfolder of the root which sucks. I want to setup a subfolder structure to organize my domains.. I called godday support and they said to use redirects.. but did not know how to do that..

How its setup now:

primary domain: / /sub

I want to create a directory structure and then redirect to each but only show in the url /domain/www /domain/sub

I tried using:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ domain/www [L]

but it just changes the url to

Can this be done in htaccess?

share|improve this question

migrated from Feb 21 '11 at 6:10

This question came from our site for professional and enthusiast programmers.

2 Answers 2

I run my own server on a similar principle, this is my configuration:

It should work with little modification for you assuming that GoDaddy supports this type of thing (it seems to from your question), except you'll need to change paths obviously. This configuration rewrites into folders like /var/www/vhosts/ for

RewriteEngine on

# Directory listing icons!
RewriteRule   ^/icons/(.*)$   /var/www/icons/$1       [L]

# Ensure there is no www.
RewriteCond   %{HTTP_HOST}    ^www\.(.*)$     [NC]
RewriteRule   ^(.*)$          http://%1$1     [R,L]

# Special case for the base domain
RewriteCond   %{HTTP_HOST}    ^(localhost|[^.]+\.[^.]{1,8}(\.au)?)$   [NC]
RewriteRule   ^(.*)$          /var/www/vhosts/%1/www$1

# Rewrite subdomains into subdirectories
RewriteCond   %{HTTP_HOST}    ^(.*?)\.(localhost|[^.]+\.[^.]{1,8}(\.au)?)$   [NC]
RewriteRule   ^(.*)$          /var/www/vhosts/%2/%1$1
share|improve this answer

Let if your original document root is point to /user../public_html/ and you want to change that document root to /user../public_html/ try this conf on your.htaccess to change your document root to /domain/www

RewriteEngine on
RewriteRule ^/$ /domain/www/

Taken from How to modify httpd>documentroot via .htaccess?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.