htaccess redirect to subdomain via SSL - .htaccess

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

Related

Redirect both domain and subdomains to https in .htaccess

How to use RewriteEngine to redirect both domain and all subdomains to https and www.domain.tld to https://domain.tld using relative path?
Currently I am using something like this
DirectoryIndex index.php
AddDefaultCharset UTF-8
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Which enables redirection of everything to https without www, I can see that some subdomains are redirecting as well, but mail.domain.tld is still available on http, no matter what I am doing.
Note that I am running roundcube on that subdomain and don't have access to this directory so I can't put another .htaccess to mail.domain.tld dir.

Add-On Domain Redirects to HTTPS

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]

How can I include a subdomain in my htaccess that forces HTTPS?

There is an htaccess file in the root directory of my domain. I added a subdomain called dev so I can work on the application from there. I think the htacccess file is preventing me from visiting the subdomain because it is rewriting the url to the main domain. How can I add a rule that rewrites the url of the subdomain to HTTPS? The main domain still works fine but I get Error 500 when I visit dev.{site_name}.php and {site_name.ph}/dev The url of the subdomain would be https://www.{site_name}.ph
RewriteEngine On
RewriteCond %{HTTP_HOST} ^{site_name}\.ph [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.{site_name}.ph/$1 [R,L]
You can use this rule to force http->https in all the domains:
RewriteEngine On
# RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

123-reg subdomain redirect to secure URL

I manage the DNS of a URL through 123-reg. I'm looking to create a subdomain and have it redirect to a specific folder of a secure URL for example https://sub.url.com/folder. How can I do this?
You can do this with some htaccess on the root folder of your domain.
ie:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(sub.)?url.com$
RewriteRule ^(/)?$ FOLDER [L]
Re-reading your question..
if users come on a non secure URL, you can always redirect them first to HTTPS like so
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
then redirect to the subfolder.

htaccess redirect .co.uk to .com for all pages

Im migrating my website from the .co.uk to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly.
ie i want http://www.mydomain.co.uk/shopping/product1 to go to http://www.mydomain.com/shopping/product1
I have done this before but for the life of me cannot remember how.
many thanks
paul
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
This redirects both the www and non-www for mydomain.co.uk to www.mydomain.com.
To redirect any (sub-)domain other than mydomain.com, use
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
Might be useful if you have other domains pointing to the same website.
It also redirects the www.mydomain.com to mydomain.com.
This is accomplished using a simple rewrite placed in your .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

Resources