Take the 2-minute tour ×
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:

www.domain.com /
sub.domain.com /sub

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

www.domain.com /domain/www
sub.domain.com /domain/sub

I tried using:

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

but it just changes the url to www.domain.com/domain/www

Can this be done in htaccess?

share|improve this question

migrated from stackoverflow.com 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/example.com/www for www.example.com.

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 www.domain.com document root is point to /user../public_html/www.domain.com/ and you want to change that document root to /user../public_html/www.domain.com/domain/www try this conf on your.htaccess to change your www.domain.com 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

 
discard

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