.htaccess | force HTTPS for primary domain, HTTP for subdomains | Help?

Howdy WPMUDev,

I got some .htaccess help the other day from WPMUDev in testing out a setup with CloudFlare in this thread from @ajay and @tyler Postle and am hoping they weigh in on this one too.

Now I have settled upon my approach and have a few .htaccess needs to work out as the final pieces.

I have just installed WP via my cpanel UI, choosing https://tivism.com as the install location.

My issue is that both HTTP and HTTPS are resolving, which creates a duplicate content situation.

1) At this point, my need is trying to find some simple .htaccess rules which will redirect all primary domain traffic to HTTPS.

However, my next step is to enable a subdomain based multisite and I know from my prior testing at my host that issues exist with having the WP primary setup at HTTPS unless symlinks are created by the server admin (or by me via cpanel cron) to match any subdomains created in WP. Obviously, this isn’t ideal, but it works for now.

However, I am waiting for the next release of Domain Mapping and then for MarketPress 3.0 wherein we will be able to use HTTPS subdomains to great advantage – I’m hopeful, but it will likely be awhile before these solutions are ready for live use.

So, in the meantime, my need here is to

2) use .htaccess rules which will redirect ALL subdomain traffic to HTTP.

Recap 1) This would mean that http://tivism.com http://www.tivism.com and https://www.tivism.com always redirect to https://tivism.com

Recap 2) This would mean that any subdomain of tivism.com (except some standardized ones like ‘www’ ? ) would always redirect to it’s HTTP address from HTTPS.

Can you please help me get these rules put together?

I have searched online and experimented for days now and am not really having luck.

From what I’ve gathered, it seems that these goals should be doable via .htaccess, and that they may even be relatively simple sets of rules. Simple they may be, but they’ve proven to be well beyond my ability to figure out thus far. :slight_smile:

(Hopefully mapped domains with ‘www’ would not be affected – eg. http://www.tivism.org –> http://tivismorg.tivism.com)

My host at first suggested doing my redirects in the database.

My understanding of these topics is improving, but still only about two inches deep. :stuck_out_tongue:

I want to do this in .htaccess specifically vs in the database for several reasons:

*I am leery of changing things in the database and causing unintentional consequences, perhaps later on.

*I am hoping to be able to ‘roll back’ the subdomain redirect rules when Domain Mapping is ready to successfully do SSL admin on ‘original’ subdomain addresses for mapped domains.

*I have been advised about performance:

“Visitor => DNS => Host => Server => Apache => PHP => MySQL

Apache is faster than MySQL, so if you handle this using your htaccess file you will save a few precious miliseconds making your site load faster.”

*I’m thinking that getting the redirects done in .htaccess reduces server load for the basically same reasons that user load times are improved

Please let me know if I have been unclear of my goal here. Thanks :slight_smile:

Best Regards,

Max