HTTPS not respecting index.php rewrite
Posted: 20 August 2008 02:35 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  8
Joined  07-31-2007

The goal: have certain URLs under SSL and others not.

The problem: When hitting the site under HTTPS, it isn’t respecting my .htaccess file and the rewrite of the URL to remove /index.php/.

I have tried several of the methods listed on this page and, no matter what I do I can’t seem to get the server to run under HTTPS without index.php in the URL:

Doesn’t work: https://example.com/shop/ (returns a 404: The requested URL /shop was not found on this server.)
Works: https://example.com/index.php/shop/

Here’s what I currently have in my .htaccess:

# Setup
Options +FollowSymlinks
RewriteEngine on
RewriteBase
/

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} (register|login|checkout)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]

RewriteCond %{REQUEST_URI} !(register|login|checkout)
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]

# rewrite out index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]

I’m the first to admit I don’t know a whole lot about HTTPS configuration, but is it possible I’m missing something there?

 Signature 

Aaron Gustafson
Principal
Easy! Designs, LLC

Profile
 
 
Posted: 20 August 2008 03:36 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  8
Joined  07-31-2007

I think I found the answer: the rewrite stuff needs to exist in the SSL virtual host as well.

Here’s my final .htaccess:

# Setup
Options +FollowSymlinks
RewriteEngine on
RewriteBase
/

RewriteCond %{REQUEST_URI} (register|login|checkout)
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# rewrite out the index.php page
RewriteCond $1 !^(images|img|css|js|log|scripts|templates|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ index.php/$1 [L]

And in the SSL config:

# Rewrite
Options +FollowSymlinks
RewriteEngine on

RewriteCond
%{REQUEST_URI} !(register|login|checkout)
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond $1 !^(images|img|css|js|log|scripts|templates|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ /index.php/$1 [L]

 Signature 

Aaron Gustafson
Principal
Easy! Designs, LLC

Profile
 
 
Posted: 20 August 2008 06:52 PM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23477
Joined  05-20-2002

Thanks for coming back with the solution.  I dropped a link in the wiki back to here.  I suspect I’ll find this useful in the near future.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 21 August 2008 07:27 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  8
Joined  07-31-2007

It’s important to note, actually, that in the SSL config, these additions were added directly to the VirtualHost, so you can’t set a RewriteBase. That means including the initial slash in the second RewriteRule and that any directory matches you want in that RewriteCond need to start with \/, so I should have written that

RewriteCond $1 !^(\/images|\/img|\/css|\/js|\/log|\/scripts|\/templates|\/themes|favicon\.ico|robots\.txt|index\.php) [NC]

Not that most of that stuff is going to be delivered over SSL per the previous RewriteRule.

 Signature 

Aaron Gustafson
Principal
Easy! Designs, LLC

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64491 Total Logged-in Users: 55
Total Topics: 81032 Total Anonymous Users: 26
Total Replies: 436048 Total Guests: 266
Total Posts: 517080    
Members ( View Memberlist )