2

I want to load my new website from subdirectory including default index.html page.

In my public_html, I have /oldsite/ and /newsite/ folders...

Then.. When I access to http://www.mysite.com/.. i want it to load all contents from http://www.mysite.com/newsite/ without redirecting. I want to do it with .htaccess mod_rewrite if possible..

Can anybody help me out with this. How to do this?

JJ.
  • 5,155
  • 3
  • 23
  • 30

2 Answers2

7
# to ensure that server already know that you going to use mod-rewrite
RewriteEngine on
# if the request from http is mysite.com or www.mysite.com go to next line (else abort)
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# if the request destination is not the folder /newsite go to next line
RewriteCond %{REQUEST_URI} !^/newsite/
# if the requested name is not an existed file in public_html directory
RewriteCond %{REQUEST_FILENAME} !-f
# if the requested name is not an existed directory in public_html directory
RewriteCond %{REQUEST_FILENAME} !-d
# forward request to /newsite/
RewriteRule ^(.*)$ /newsite/$1
# if the request domain is mysite.com (with out any string afterward), go to next line
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# forward request to the default file under newsite directory
RewriteRule ^(/)?$ newsite/ [L]
jurijcz
  • 356
  • 1
  • 11
  • Thanks for posting. This solved my problem. I tried it with `RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$` followed by `RewriteRule ^(.*)$ /newsite/$1 [QSA,L]` but that didn't work. – Volomike Jul 31 '12 at 19:29
0

It is generally not a good idea to deploy a website like this. Instead you should create virtual hosts for the live and development versions of your site. If you can't do that with your current hosting provider you can make use of symlink for public_html and when the new version is ready to go live just change its path. Hope that helps.

Vladimir
  • 808
  • 5
  • 13