简体   繁体   English

将AP中的某些页面的http重定向到https

[英]redirect http to https for some page in site in APACHE

I want to one of my site's page will use only HTTPS. 我希望我网站的其中一个页面只使用HTTPS。

I have given manually link to all sites to https . 我手动链接到所有站点到https

But I want that if user manually types that page URL with http then it should be redirected to https page. 但我希望如果用户用http手动键入该页面URL,则应将其重定向到https页面。

So if user types: 所以如果用户输入:

http://example.com/application.php

then it should be redirected to 然后它应该被重定向到

https://example.com/application.php

Thanks 谢谢
Avinash 阿维纳什

Here's a couple of lines I used in an .htaccess file for my blog, some time ago : 不久之前,我在博客的.htaccess文件中使用了几行:

RewriteCond %{HTTP_HOST}  =www.example.com                        
RewriteCond %{REQUEST_URI} ^/admin*                                     
RewriteCond %{HTTPS} !=on                                               
RewriteRule ^admin/(.*)$  https://www.example.com/admin/$1 [QSA,R=301,L]


Basically, the idea here is to : 基本上,这里的想法是:

  • determine whether the host is www.example.com 确定主机是否为www.example.com
  • and the URL is /admin/* 并且URL是/ admin / *
    • Because I only wanted the admin interface to be in https 因为我只希望管理界面在https中
    • which means this second condition should not be useful, in your case 这意味着在您的情况下,第二个条件不应该有用
  • and https is off (ie the request was made as http) 和https关闭(即请求是作为http)

And, if so, redirect to the requested page, using https instead of http. 如果是这样,请使用https而不是http重定向到请求的页面。


I suppose you could use this as a starting point, for your specific case :-) 我想你可以用它作为起点,针对你的具体情况:-)

You'll probably just have to : 你可能只需要:

  • change the first and last line 改变第一行和最后一行
  • remove the second one 删除第二个


Edit after the comment : well, what about something like this : 评论后编辑:好吧,这样的事情:

RewriteCond %{HTTP_HOST}  =mydomain.com
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$  https://mydomain.com/$1 [QSA,R=301,L]

Basically : 基本上:

  • using your own domain name 使用您自己的域名
  • removing the parts about admin 删除有关admin的部分

Try this rule: 试试这条规则:

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

This rule is intended to be used in the .htaccess file in the document root of your server. 此规则旨在用于服务器的文档根目录中的.htaccess文件中。 If you want to use it in the server configuration file, add a leading slash to the pattern of RewriteRule . 如果要在服务器配置文件中使用它,请在RewriteRule模式中添加前导斜杠。

use this: 用这个:

RewriteEngine On
# Turn SSL on for /user/login
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/user/login
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

# Turn SSL off everything but /user/login
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/user/login
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [R=301,L]

website 网站

open httpd.conf or .htaccess file (mod_rewrite not required): 打开httpd.conf或.htaccess文件(不需要mod_rewrite):

# vim httpd.conf

Append following line : 附加以下行:

Redirect permanent / https://example.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM