0

In our app we allow custom domains, so a user can create:

custom.my.example.com

Which we map to:

app.our.example.com

In our app we enforce SSL, except for when the user enters a preview URL such as this:

custom.my.example.com/preview/blah

Currently if users just type "custom.my.example.com" they receive an SSL error as the current rules only exempt /preview/blah from the forced redirect. How can I create a rule so that if a user enters "custom.my.example.com" without /preview it redirects them to http://custom.my.example.com/domain to show a special message?

Current .htaccess rules:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/preview
RewriteCond %{QUERY_STRING} !^/preview
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

We are using CodeIgniter on CentOS 6.5 with Apache 2.2.

Thanks!

Jenny D
  • 28,400
  • 21
  • 80
  • 117
Jonathan
  • 207
  • 6
  • 10

1 Answers1

0

Fixed! Here's the updated rewrite:

RewriteEngine On
RewriteBase /

# start new rules
RewriteCond %{HTTP_HOST} !^(.*).ourdomain.com
RewriteCond %{REQUEST_URI} !^/preview
RewriteCond %{QUERY_STRING} !^/preview
RewriteRule ^(.*)$ https://app.ourdomain.com/domain [L,R=301]
# end new rules

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/preview
RewriteCond %{QUERY_STRING} !^/preview
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Jonathan
  • 207
  • 6
  • 10