从子目录加载新站点作为索引

Bor*_*vic 2 .htaccess mod-rewrite

我想从子目录加载我的新网站,包括默认的index.html页面.

在我的public_html中,我有/ oldsite /和/ newsite/folders ...

然后..当我访问http://www.mysite.com/ ..我希望它从http://www.mysite.com/newsite/加载所有内容而不重定向.如果可能,我想用.htaccess mod_rewrite来做..

任何人都可以帮我解决这个问题.这该怎么做?

jur*_*jcz 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]
Run Code Online (Sandbox Code Playgroud)