仅HTTPS上的.htaccess特定页面页面、HTTPS、htaccess

2023-09-02 11:26:00 作者:刀锋战神

我有一个URL,例如 http://www.domain.com/index.php?p=register 。我想重定向使用HTTPS(SSL)和htaccess的,但只有在此,和几个其他网页(登录页面,等等),而不是整个站点。该网址不会指向的目录,而是用于动态包含不同的文件。

I have a URL such as http://www.domain.com/index.php?p=register. I want to redirect that to use HTTPS (SSL) with .htaccess, but only on this, and a couple of other pages (the login page, etc), but not the entire site. The URLs don't point to directories, but are used to dynamically include different files.

有人可以给我一个指针或如何得到一个单页的例子重定向到HTTPS好吗?

Can someone give me a pointer or an example of how to get a single page redirect to HTTPS please?

感谢。

推荐答案

不是htaccess的,但另一种可能是使用PHP来重定向:

Not htaccess, but another way could be to use PHP to redirect:

<?php

$redirectlist = array('register','login','myaccount');

if (in_array($_GET['p'], $redirectlist) && strtolower($_SERVER['HTTPS']) != 'on') {
    exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"));
}

?>

我提到这一点的唯一原因是,在一些情况下,这可能会更容易比单独htaccess的维护。您需要把这个地方你的PHP内容的任何文本中输出之前(见头() )。