2013-01-15 51 views
0

我試圖將一些安全頁面添加到網站。站點中的鏈路全部使用當前協議(即獨立於協議,路徑始於//)。http/https重寫不工作,將index.php添加到路徑

我需要路徑/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/,而不是重定向到HTTPS版本,我得到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

我已經解決了這個問題,不是用htaccess,而是在index.php文件中(所有的請求都經過這個)。

默認情況下,我假設端口80。然後,如果$_SERVER['REQUEST_URI']位於安全路徑陣列中,則將該變量切換爲443

然後,如果$required_port != $_SERVER['SERVER_PORT'],我重定向和exit()