[英]HTTPS only on specific page with .htaccess
I have a URL such as http://www.domain.com/index.php?p=register
. 我有一个URL,例如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. 我想重定向使用HTTPS(SSL)与.htaccess,但仅限于此,以及其他几个页面(登录页面等),但不是整个站点。 The URLs don't point to directories, but are used to dynamically include different files. URL不指向目录,但用于动态包含不同的文件。
Can someone give me a pointer or an example of how to get a single page redirect to HTTPS please? 有人可以给我一个指针或一个如何让单个页面重定向到HTTPS的例子吗?
Thanks. 谢谢。
Not htaccess, but another way could be to use PHP to redirect: 不是htaccess,但另一种方法可能是使用PHP重定向:
<?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']}"));
}
?>
The only reason I mention this is that, in some cases, this may be easier to maintain than a separate htaccess. 我提到这一点的唯一原因是,在某些情况下,这可能比单独的htaccess更容易维护。 You would need to put this in place in your PHP content before any text was outputted (see header() ). 在输出任何文本之前,您需要在PHP内容中放置它(请参阅header() )。
something like this should work: 这样的事情应该有效:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{QUERY_STRING} (^|&)p=(register|login|or|other|protected|page)($|&)
RewriteRule (.*) https://www.domain.com/index.php [R=301,QSA,L]
Some explanation: 一些解释:
If you have option to follow the php method, I would recommend to follow that or with any other dynamic languages. 如果您可以选择遵循php方法,我建议您遵循该方法或使用任何其他动态语言。 You must avoid using htaccess since links to images, js and other contact on that page will be forced to be nonSSL and modern browsers would show a non-compliance sign which might look a whitewash over your SSL cost. 您必须避免使用htaccess,因为该页面上的图像,js和其他联系人的链接将被强制为非SSL,而现代浏览器将显示不合规标志,这可能看起来对您的SSL成本进行粉饰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.