开发者

SSL rewrite redirection apache2

I have two virtual hosts set to the same directory on the server. One listens on port 80 and the other on 443.

I have 3 files

index.html
secure.html
view.html

Each file has a menu:

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

I would like to set redirecting so it meets these conditions:

http://localhost/secure.html - goes to https://localhost/secure.html

http://localhost/index.html 开发者_JAVA技巧- goes to http://localhost/index.html

http://localhost/view.html - goes to http://localhost/view.html

https://localhost/index.html - goes to http://localhost/index.html

https://localhost/view.html - goes to http://localhost/view.html

and when I'm in

https://localhost/secure.html and I click on

Index takes me to http://localhost/index.html

View takes me to http://localhost/view.html

How could I achieve this?

I know I have to put these in .htaccess file but I don't know how to define these confitions,


Try these two rules:

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]

If you have more than this single file, just extend the pattern like ^/(secure\.html|…)$.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜