-1

I have a set of code that redirects from a file called package.php to a "pretty permalinks" structure. The problem is that it doesn't redirect to the https version of the page. I need to be able to redirect to https://www.example.com/package-type/airport-name/hotel-name. Here is the code:

#Redirects hotel pages to package.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /package.php?/$1 [L]

# Removes package.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*package\.php [NC]
RewriteCond %{REQUEST_URI} !/.* [NC]
RewriteRule (.*?)package\.php/*(.*) /$1$2 [R=301,NE,L]

I do have redirection code that detects if https is off and redirects to the correct version. But this code doesn't get called until after the above code.

#First rewrite
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

I am not looking to combine the two sections of code. That would break other pages that are not package pages. Instead I need the first set of code to redirect to https version of the pages.

Any help would be appreciated.

Daniel Harris
  • 1,805
  • 10
  • 45
  • 63

1 Answers1

0

Try these rules:

# Removes package.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*package\.php [NC]
RewriteCond %{REQUEST_URI} !/.* [NC]
RewriteRule (.*?)package\.php/*(.*) https://%{HTTP_HOST}/$1$2 [R=301,NE,L]

#Redirects hotel pages to package.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /package.php?/$1 [L]

Make sure to clear your browser cache before testing this change.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • https://www.example.com/package.php?/package-type/airport-name/hotel-name/2-people – Daniel Harris Oct 19 '15 at 16:16
  • So `https://www.example.com/package-type/airport-name/hotel-name` is causing 404 but `http://www.example.com/package-type/airport-name/hotel-name` works fine? – anubhava Oct 19 '15 at 16:38
  • You seem to be bit confused I think. When I asked what URL is causing 404 you gave `https://www.example.com/package.php?/package-type/airport-name/hotel-name/2-people` – anubhava Oct 19 '15 at 16:40
  • `http://www.example.com/package.php?/package-type/airport-name/hotel-name/2-peo‌​ple` is causing 404. – Daniel Harris Oct 19 '15 at 16:41
  • Show your `VirtualHost` config for `https` in question. – anubhava Oct 19 '15 at 16:44