我正在尝试向网站添加一些安全页面。站点中的链接都使用当前协议(即,与协议无关,路径以//
开头)。
我需要使用路径/info/season-tickets/*
和/ticketcontroller/*
来使用https,其他所有路径都使用http。
我已经尝试构建规则来执行以下操作(暂时忽略ticketcontroller部分):
If Port==80 and Path==/info/season-tickets/, rewrite with https
If Port==443 and Path!=/info/season-tickets/, rewrite with http
但是,当我访问/info/season-tickets/
时,我得到example.com/index.php/info/season-tickets
.htaccess低于 - 我的尝试低于# Force https on certain pages
和# Force http everywhere else
,其他位来自Kohana框架
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Force https on certain pages
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/info/season-tickets/?
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# Force http everywhere else
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/info/season-tickets/?
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
我尝试重新排序规则,看看是否修复了它,但事实并非如此。
为什么这不起作用的任何想法(http://htaccess.madewithlove.be/
表明它应该有效)...
谢谢!
答案 0 :(得分:0)
我已经解决了这个问题,不是用htaccess,而是在index.php文件中(所有请求都经过这个)。
默认情况下,我假设端口80
。然后,如果$_SERVER['REQUEST_URI']
位于安全路径数组中,我将变量切换为443
。
然后,如果$required_port != $_SERVER['SERVER_PORT']
,我会重定向并exit()
。