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 defined a host in my CPanel\WHM server and put all my websites under one host account. The host Main Domain is domain.com, and all other websites are Add-on Domains:

domain.com
  --folder
  --domain1
  --domain2
  --domain3
  ...

The thing I need is that when calling domain.com in browser, the server read files from another folder. for example when call http://domain.com it shows us http://domain.com/folder BUT I don't mean a redirection, I want server do this in background without showing visitors the real path.

I couldn't do this with Domain WildCard Redirection because it got error.

How can I do this? With htaccess or ... ?

share|improve this question

migrated from stackoverflow.com Aug 3 '11 at 16:11

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

add comment

1 Answer 1

The best would be just point domain into that folder in your Control Panel.

If it is necessary to be done with .htaccess and mod_rewrite, then here are the rules:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/folder/
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -d
RewriteRule (.*) /folder/$1 [L]

For the above to work you need to:

  • place this into .htaccess file in website root folder;
  • have mod_rewrite enabled on your server;
  • .htaccess is enabled in server config and allowed to contain rewrite rule directives (AllowOverride All or similar).

Consult your hosting company with the last 2 points.

share|improve this answer
    
Thanks, the problem solved with this But another problem made, Add-on domains and sub domains don't load now and they get "Not Found 404" error. –  Memphis Raines Jul 29 '11 at 15:24
    
@Memphis Raines Please explain, I don't know how your system works. Possibly rule needs to be rewritten to accommodate this new information (depends on details you provide). –  LazyOne Jul 29 '11 at 15:30
    
There is a CPanel\WHM Host Account. The Main Domain for this Host Account is one of my domains named domain.com , All other my domains (websites) added to this host account (Add-on domains) and the files of each one located in seperate folder. Of course the folder of the domain.com (main domain) is a level up of all them, so we have this schema: -domain.com --folder --website1 --website2 --website3 ... i if someone call domain.com the server shows him the files located in top folder that includes other websites folder like website1, website2, ... . I create another folder here named –  Memphis Raines Jul 29 '11 at 15:46
    
"folder" and i want the files of domain.com read from this folder... I can't do "WildCard Redirect" from http://[www.]domain.com to http://[www.]domain.com/folder because the CPanel show an error message. So i thought we can do samething via htaccess file rules. i need the server loading data of Domain.Com Website from a seperate folder not the top one. –  Memphis Raines Jul 29 '11 at 15:46
    
@Memphis Raines See updated rule -- it will check if such file/folder does exist in /folder/ before rewriting it. I'm still unclear on how your system works. As I understand folder and domain1, domain2 folders are all on the same level. –  LazyOne Jul 29 '11 at 15:53
show 2 more comments

Your Answer

 
discard

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