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

标签 .htaccess mod-rewrite

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

在我的 public_html 中,我有/oldsite/和/newsite/文件夹...

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

任何人都可以帮我解决这个问题吗?如何做到这一点?

最佳答案

# 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]

关于.htaccess - 从子目录加载新站点作为索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7214300/

相关文章:

javascript - Ajax:rest api 调用给出错误:未捕获的语法错误:意外的标记:

apache - .htaccess - 强制 www、尾部斜杠并删除扩展名

apache - 通用 mod_rewrite 引用检查

regex - 仅将子域重定向到根

php - 显示子域根目录下域文件夹的内容

.htaccess - 将请求重定向到与模式不匹配的目录

html - 如何阻止直接访问 Apache 中的特定目录和文件?

regex - htaccess 重定向 + 隐藏 url 中的子文件夹

php - .htaccess PHP $_GET

.htaccess - 使用 .htaccess 仅授予对一个目录的访问权限