操作系统:CentOS 5.3 Apache 2.2.3
假设我在机器上托管了两个网站 (/var/www/html/site1 和 /var/www/html/site2)。目前,
http://hostname/site1
http://hostname/site2
带到网站上。和 http://主机名 进入 Apache 欢迎页面。有什么方法可以实现 (http://主机名) 只需更改配置而不移动文件夹结构即可直接转到 site1?非常感谢!!
答案1
你想要其中一个Redirect*
指令。
答案2
我在下面找到了答案。
# Turn on rewrites.
RewriteEngine on
# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^192\.168\.1\.100$ (this seems unnecessary)
# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/site2/
RewriteCond %{REQUEST_URI} !^/site2
# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /site2/$1
# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^192\.168\.1\.100$
RewriteRule ^(/)?$ /site2/index.php [L]
RewriteCond %{HTTP_HOST} ^myHost\.com$
RewriteRule ^(/)?$ /site2/index.php [L]
所以现在http://192.168.1.100将重写为http://192.168.1.100/site2/ 但是,我还设置了一个 DNS,使 myHost.com 解析为 192.168.1.100。现在重写不起作用http://myHost.com 有人能帮忙吗?非常感谢!
编辑:刚刚通过添加另一个重写规则找到了解决方案。