2010-12-15 89 views
0

我有两台虚拟主机设置为服务器上的同一目录。一个监听80端口,另一个在443SSL重写重定向apache2

我有3个文件

index.html 
secure.html 
view.html 

每个文件都有一个菜单:

<ul> 
<li><a href="index.html">Index</a></li> 
<li><a href="secure.html">secure</a></li> 
<li><a href="view.html">view</a></li> 
</ul> 

我想设置重定向,以使其符合这些条件:

http://localhost/secure.html - 去https://localhost/secure.html

http://localhost/index.html - 去http://localhost/index.html

http://localhost/view.html - 去http://localhost/view.html

https://localhost/index.html - 去http://localhost/index.html

https://localhost/view.html - 去http://localhost/view.html

,当我在
https://localhost/secure.html和我点击

指数带我到http://localhost/index.html

查看带我到http://localhost/view.html

我怎么能做到这一点?

我知道我必须把这些在.htaccess文件,但我不知道如何定义这些confitions,

+0

属于[serverfault](http://serverfault.com/)。 – 2010-12-16 01:30:26

回答

1

尝试这两个规则:

RewriteCond %{HTTPS} !=on 
RewriteRule ^/secure\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTPS} =on 
RewriteRule !^/secure\.html$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

如果你有比这多单文件,只需扩展^/(secure\.html|…)$这样的模式即可。