访问网站只能通过HTTP,除了2页 [英] Access website only by HTTP except for 2 pages
问题描述
我需要用户通过HTTPS访问我的网站帮助。我只想有2个页面能够通过HTTPS访问。其他所有的页面应该只访问HTTP,如果用户试图通过HTTPS访问该页面会重定向到该网页的HTTP版本。我尝试了好几种.htaccess文件,但我似乎无法得到其中的任何工作。
I need help with users accessing my site via HTTPS. I only want to have 2 pages able to be accessed via HTTPS. All other pages should be accessed HTTP only and if the user tries to access the page via HTTPS it will redirect them to the HTTP version of that page. I have tried several .htaccess files but I cannot seem to get any of them to work.
任何帮助是极大AP preciated!
Any help is greatly appreciated!
推荐答案
几个不同的方式:
-
您既可以放置一些逻辑在2页(
enroll.php
和Registered.php
)重定向到HTTPS。
You could either place some logic in the 2 pages (
enroll.php
andRegistered.php
) to redirect to HTTPS.
if ($_SERVER['HTTPS']!="on")
{
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}
假设你正在使用的Apache Web服务器(其它Web服务器包括IIS与重定向机制非常相似),你可以使用模式匹配和这两个网址,指定一个重定向到HTTPS。
Assuming you are using Apache Web Server (other web servers including IIS are fairly similar with redirect mechanism), you can employ pattern matching and for these two URLs, specify a redirect to HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (enroll.php) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule (Registration.php) https://%{HTTP_HOST}%{REQUEST_URI}
这篇关于访问网站只能通过HTTP,除了2页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!