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

时间:2011-08-27 11:41:49

标签: .htaccess mod-rewrite

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

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

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

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

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

部署这样的网站通常不是一个好主意。相反,您应该为站点的实时和开发版本创建虚拟主机。如果您不能对当前的托管服务提供商执行此操作,则可以使用symlink for public_html,当新版本准备好上线时,只需更改其路径即可。希望有所帮助。