Add-On Domain Redirects to HTTPS - .htaccess

I have a GoDaddy shared hosting account with one main domain that uses SSL and now an add-on domain that I do not want to use SSL. I would like to redirect non-https to https for the main domain BUT NOT for the add-on domain. Both sites use Wordpress.
To be clear, the main domain should use https, the add-on domain should not use https.
The problem I am experiencing is addondomain.com is redirecting to https://addondomain.com.
I know the problem can be fixed through my .htaccess file, and I have made several attempts, but each one ends with the add-on domain redirecting back to the main domain. Any insight as to what I need to change on my .htaccess file would be very much appreciated!
Here is what my .htaccess file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

If you want to redirect just the maindomain to https, just add the following condition to your rule :
RewriteEngine On
##if host=="*maindomain.com"##
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$
##and scheme ==http(https off)##
RewriteCond %{HTTPS} off
##then redirect the site to https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Related

htaccess redirect to subdomain via SSL

My domain is https://webkust.be, now i trying made a subdomain https://labs.webkust.be
I used Direct Admin and SSL (Let's Encrypt)
So in the /public_html/, set this in htaccess:
## REDIRECT TO HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$
https://www.webkust.be/$1 [R,L]
</IfModule>
Adding the website in /private_html/
This works perfect for webkust.be
But now i try adding a new subdomain on the same hosting https://labs.webkust.be
This doesn't work.
Is there a way redirecting the subdomain to https://?
You can try:
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
It should work for subdomains as well. Docs

Forcing https in .htaccess

I try to force https in .htaccess as such:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
# END WordPress
It works when I try www.example.com, but if I try something like www.example.com/contact-us, it is still with http. Is there something wrong with my .htaccess?
Note I do not have access to the cPanel (hosted on crazydomain) nor Wordpress admin. So upload my .htaccess is my only option.
All rules are applied in order. You have rules before the rule handling HTTPS redirects, and those rules all end with [L], meaning that rule evaluation will stop there.
Put your HTTPS redirect first before caring about more detailed pages and files.

Forcing SSL only on the main domain on cPanel

I currently have 3 domains on my cPanel account with HostGator. I am trying to force the main domain to use HTTPS, but all other domains to use HTTP. When I add the following to the main directories .htaccess file, it forces it upon all sub-directories too.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Is there any way to not make it do this on the other domains?
You just need another RewriteCond and check for the HTTP_HOST so that the RewriteRule is not applied to domains that don't need to have https:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^no-https-needed.example.com$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Mod Rewrite - multiple condition

I have a certain sub-domain which requires an SSL connection for all pages on that subdomain.
This is my current .htaccess script:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
I have a single page on the subdomain which must not have SSL access (causes issues with accessing files on another server without a certificate).
My mod_rewrite knowledge is very limited. I've done a search but can't find what I need.
My question is, the page which must not have https is called 'tutorial.php'. Is there a way to redirect all pages except tutorial.php to https?
I guess in pseudo-code, the RewriteCond would be similar to:
RewriteCond %{SERVER_PORT} 80 AND {WEB_PAGE}!='tutorial.php'
Thanks
Try this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/tutorial\.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTPS} on
RewriteRule ^tutorial\.php$ http://%{HTTP_HOST}/tutorial.php [R,L]

How to implement dynamic subdomains in codeigniter with .htaccess?

How can I implement dynamic subdomains in codeigniter with .htaccess?
Make sure that subdomains are enabled on your site. When you enter test.yoursite.com it should take you to the welcome page of your site. If instead it gives DNS lookup error then it means subdomains is not enabled on your site.
To enable subdomains on your site add *.yoursite.com entry to the DNS Zone records.
Second insert the following code in your .htaccess file and replace yoursite appropriately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#this rule removes www from the URL if its used
RewriteCond %{HTTP_HOST} ^www.
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
#the auth system URIs which don't have subdomains
RewriteCond %{HTTP_HOST} ^yoursite.
RewriteRule ^(signup|signin|forgot_password)/?$ index.php?/auth/$1 [L]
#this rule handles the subdomains
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).yoursite.com
RewriteRule ^(.*)$ index.php?/public_site/%1/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Add more rules, if necessary, for handling auth system or subdomains. I know I did for my site to get pretty URIs.
Important Note:
I found that by default the subdomain URIs work very well with codeigniter without any of the above rules. You can access all of your site with test.yoursite.com/# URI instead of www.yoursite.com/#. But the URIs are not pretty and there would be more than one way to access a URI.
So if you use the above rules it will give you pretty URIs and, more importantly, will give you unique URIs. So if you use the above rules you will only get one URI for the signup page and that is http://yoursite.com/signup.
this code is working for my site, you can move your site into your other domain or folder ( whatever you want ).
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|application/assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
This rule handles the subdomains
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).yoursite.com. should probably also include the hypen -. RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).yoursite.com.

Resources