htaccess的 - 如何设置SSL在某些页面(脚本需要的修改) [英] .htaccess - How to set SSL on certain pages (Script need's modifying)
问题描述
我对整个网站启用SSL,但我需要给力以外的所有网页的的login.php 和 register.php 到http://
所以基本上我只需要的login.php和register.php页面是https://开头协议-ED。
现在我有脚本,它的的login.php 页的https://加密,但我不知道如何添加 register.php 以这种code
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /
#启用SSL上的付款
的RewriteCond%{} HTTPS关闭
的RewriteCond%{SCRIPT_FILENAME} \ /登录\ .PHP [NC]
(。*)重写规则^ $的https://%{HTTP_HOST} / $ 1 [R = 301,L]
#打开SSL关闭一切,但付款
的RewriteCond%{} HTTPS上
的RewriteCond%{} SCRIPT_FILENAME!\ /登录\ .PHP [NC]
(。*)重写规则^ $的http://%{HTTP_HOST} / $ 1 [R = 301,L]
如何EDI /使这个code设置的login.php和register.php页到https的任何想法://和所有其他到http://
感谢您
如果你熟悉的mod_rewrite和正则表达式一点点,你应该没有问题,阅读这些规则 - 评论是present解释什么特定规则呢。其余的 - 正则表达式基础知识:
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
#力HTTPS进行/login.php和/register.php
的RewriteCond%{HTTPS} =关闭
重写规则^(登录|注册)\ PHP $的https://%{HTTP_HOST}%{REQUEST_URI} [R = 301,L]。
(因为是休假协议)#不做任何事的图像/ CSS / JS
。重写规则\(?GIF | JPE G | PNG | CSS | JS)$ - [NC,L]
#力HTTP的所有其他网址
的RewriteCond%{} HTTPS = ON
!的RewriteCond%{REQUEST_URI} ^ /(登录|注册)\ PHP $。
。重写规则* HTTP://%{HTTP_HOST}%{REQUEST_URI} [R = 301,L]
-
这些规则需要被放置在.htaccess在网站根目录文件夹之前任何其他重写规则(如果这样present)。如果放在其他地方的一些小的调整可能是必需的。
-
他们会
- 力HTTPS的
/login.php
和/register.php
, - 在做什么图像,CSS样式和JavaScript文件(是precise,与这些扩展名的文件)
- ,将迫使HTTP的其他所有网址
- 力HTTPS的
-
您可以轻松地为其他URL添加到列表 - 只需通过添加额外的文件名列表编辑现有规则(在2处相同的文字:1)强制2)排除)
-
文件名是区分大小写的。因此,这些规则将无法工作,如果
/LOGIN.php
要求(Apache将无法满足,要么,因为Linux是大小写敏感的操作系统..所以无需太多人担心)。 -
显而易见的事:mod_rewrite的应启用和.htaccess文件需要由阿帕奇(有些网站托管公司禁用它们的性能和安全原因)进行处理
I have ssl enabled on whole website, but I need to force all pages except login.php and register.php to http://
So basically I only need login.php and register.php pages to be https:// protocol-ed.
Right now I have script that makes login.php page https:// encrypted , but I don't understand how to add register.php to this code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Turn SSL on for payments
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/login\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Turn SSL off everything but payments
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/login\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Any ideas on how to edi/make this code to set login.php and register.php pages to https:// and all others to http://
Thank you
If you are familiar with mod_rewrite and regex a little bit, you should have no problems reading these rules -- comments are present explaining what particular rule does. the rest -- regex basics:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# force https for /login.php and /register.php
RewriteCond %{HTTPS} =off
RewriteRule ^(login|register)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
# force http for all other URLs
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(login|register)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
These rules need to be placed in .htaccess in website root folder BEFORE any other rewrite rules (if such present). If placed elsewhere some small tweaking may be required.
They will
- force HTTPS for
/login.php
and/register.php
, - do nothing for images, css styles and JavaScript files (to be precise, for files with those extensions)
- and will force HTTP for all other URLs
- force HTTPS for
You can easily add other URLs to that list -- just edit existing rule by adding additional file name to the list (the same text in 2 places: 1) to force 2) to exclude)
File names are case-sensitive. So these rules will not work if
/LOGIN.php
is requested (Apache will not serve it either, as Linux is case-sensitive OS .. so no need to worry much here).Obvious thing: mod_rewrite should be enabled and .htaccess files needs to be processed by Apache (some website hosting companies disabling them for performance and security reasons).
这篇关于htaccess的 - 如何设置SSL在某些页面(脚本需要的修改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!