Pretty URLs not working after switching to HTTPS

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am
Location: Brisbane, Australia

Pretty URLs not working after switching to HTTPS

Post by gocreative »

We've just migrated a website from HTTP to HTTPS, and taken care of all of the fundamental steps (as per below), however pretty URLs no longer work. For example:

This: https://www.gallangplace.org.au/index.php?page=services
Should be: https://www.gallangplace.org.au/services

The steps we followed were:

* Updating all domain references from http:// to https:// in files and the database (including serialised arrays)
* Specifying the HTTPS address etc in config.php
* Clearing all caches, updating routes and hierarchies etc
* Updating .htaccess to redirect from HTTP to HTTPS with wildcards

We've done this countless times on various websites, but this is the first CMS Made Simple website, and we have more to go.

Any suggestions would be greatly appreciated.

Here's our .htaccess file:

Code: Select all

############ FILE LISTINGS ############

Options -Indexes

<Files "config.php">
order allow,deny
deny from all
</Files>

############ ERROR HANDLING ############

ErrorDocument 403 /forbidden403.shtml

ServerSignature Off

############ OPTIMISATION ############

# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# compress css, text...
<FilesMatch "\.(js|css|html|htm|php|xml|htc|eot)$">
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</FilesMatch>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript image/gif text/x-js application/javascript image/x-icon
</IfModule>

# set expires headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/x-component "access plus 1 years 1 days"
</ifModule>

<ifModule mod_headers.c>
  <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|ttf|eot|woff|svg)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\\.(js|htc)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\\.(xml|txt)$">
    Header set Cache-Control "max-age=216000, public, must-revalidate"
  </filesMatch>
  <filesMatch "\\.(html|htm|php)$">
    Header set Cache-Control "max-age=1, private, must-revalidate"
  </filesMatch>
</ifModule>

# enable gzip
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl|htc|eot|ttf|woff|svg|ico|pdf|flv)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

# disable ETags
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
  FileETag None

<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>

#
# The following is to enable pretty URLs, only applicable if url_rewriting is set to 'mod_rewrite' in the config.php
#
<IfModule rewrite_module>
  RewriteEngine on
  # If your CMSMS installation is in a subdirectory of your domain, you need to specify the relative path (from the root of the domain) here.
  # In example: RewriteBase /[subdirectory name]
  #RewriteBase /

# +++++ ADD THIS - START +++++
  # Link to http(s)://website... then redirect to https://www.website...
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

  # Force URLs have https instead of http
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# +++++ ADD THIS - END +++++

# Rewrites URLs in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
  RewriteCond %{REQUEST_FILENAME} !-f [NC]
  RewriteCond %{REQUEST_FILENAME} !-d [NC]
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>

RewriteCond %{HTTP_HOST} ^gallangplace\.org\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gallangplace\.org\.au$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.gallangplace\.org\.au\/$1" [R=301,L]
And here's our config.php file:

Code: Select all

<?php

$config['ssl_url'] = 'https://www.gallangplace.org.au';
$config['root_url'] = 'https://www.gallangplace.org.au';
$config['admin_url'] = 'https://www.gallangplace.org.au/admin';

# DATABASE
$config['db_hostname'] = 'xxxxxxxxxxxxxxxx';
$config['db_username'] = 'xxxxxxxxxxxxxxxx';
$config['db_password'] = 'xxxxxxxxxxxxxxxx';
$config['db_name'] = 'xxxxxxxxxxxxxxxx';
$config['db_prefix'] = 'xxxxxxxxxxxxxxxx';
$config['dbms'] = 'mysqli';

# PRETTY URLS
$config['url_rewriting'] = 'mod_rewrite';
$config['query_var'] = 'page';
$config['internal_pretty_urls'] = true;
$config['assume_mod_rewrite'] = true;
$config['use_hierarchy'] = true;

# SERVER SETTINGS
$config['timezone'] = 'Australia/Brisbane';
$config['default_upload_permission'] = '777';
$config['debug'] = false;
?>
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: Pretty URLs not working after switching to HTTPS

Post by scooper »

It's early in the morning here for trying to work out rewrite rules (and I've not had coffee) but I think that the last redirect is your problem.

So this rule

Code: Select all

RewriteRule ^(.+)$ index.php?page=$1 [QSA]
is rewriting the url but then after that you have this rule:

Code: Select all

RewriteCond %{HTTP_HOST} ^gallangplace\.org\.au$
...
RewriteRule ^(.*)$ "https\:\/\/www\.gallangplace\.org\.au\/$1" [R=301,L]
which is redirecting the page using the url that was previously rewritten.

I'm not entirely sure what that last block of code is doing so you could either try removing it if you don't have a good reason for it, or move the rewrite rule to be the final thing in the htaccess file.
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am
Location: Brisbane, Australia

Re: Pretty URLs not working after switching to HTTPS

Post by gocreative »

Thanks! I swear I moved/deleted that block a million times. I really appreciate the fresh eyes.
Post Reply

Return to “CMSMS Core”