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
  • 27,358
  • 21
  • 74
  • 110
Jonathan
  • 197
  • 4
  • 10
  • **DO NOT** make up domain names. You don't own mydomain.com or ourdomain.com. If you are for some reason unwilling to show the actual domain names, you should use e.g. example.com or example.org which are specifically set aside for this purpose. – Jenny D Jan 05 '15 at 18:45
  • Wasn't aware of that rule sorry, is there a list of rules I can read somewhere? I chose those as examples since users are creating custom domains and we have our own. The way you changed my post makes it very difficult to tell what I was trying to accomplish. I'm not using custom subdomains, I'm using custom domain mapping with CNAME's. We also support custom subdomains which is why the rules look as the did. – Jonathan Jan 06 '15 at 02:22
  • Simple courtesy should make it clear that you don't lie to people you ask for help, and you don't use domain names that belong to other people. For further information, see http://meta.serverfault.com/questions/963/what-information-should-i-include-or-obfuscate-in-my-posts/6063#6063 As for the edit - whether the mapping is done with subdomains or not makes little difference to the solution; it's much as if you'd been in e.g. the UK where the domain would have been `example.co.uk` instead of `example.com`. – Jenny D Jan 06 '15 at 09:29
  • How did I lie..? I needed two example names so I thought those were sufficient. As I said I wasn't aware of that rule and won't do it again in the future. I've never received such agitated responses from an admin before. Nobody will understand what I meant with what you put so you might as well just delete my post. It looks like two subdomains which is not at all what I was trying to do... – Jonathan Jan 06 '15 at 17:34
  • When you are replacing the actual names with other names, you are not giving the whole truth. I am sorry that I came across as agitated; many of us have on more than one occasion wasted considerable time trying to debug e.g. DNS issues to no avail only to find out that the reason they couldn't find the issue was that the poster used someone else's domains instead of their own. So, as I said, if you do want to make up domains, then use the ones that are set aside for that purpose. You are free to edit your post again if you wish to. If you don't, it will disappear anyway soon. – Jenny D Jan 06 '15 at 17:43
  • Oh, by the way - I'm not an admin. I'm a user here. I can't delete your question; all I can do is cast votes. (And, to build on the previous comment - I have spent time locating a tiny spelling error in a RewriteRule, only to find that the spelling error was introduced by the poster who was trying to hide their domain, just like you did, and the actual config didn't contain that error. It just makes **no** sense to me why someone will trust random people of the internet enough to ask for their help, but not enough to give them correct information to work with.) – Jenny D Jan 06 '15 at 17:47

1 Answers1

-1

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
  • 197
  • 4
  • 10
  • 2
    To make this site better to people, try to explain what was wrong and why this is the solution. – ETL Jan 05 '15 at 17:42