Redirect Domain & Sub-domain to HTTPS - .htaccess

I am trying to redirect my domain and sub domain to https. I have subscribed to Wildcard SSL and made below modifications to htaccess file, as per this guide.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I am now seeing HTTPS 'Secure Connection' on my main domain. But on sub-domain, it is still showing 'Not Secure' although HTTPS is in the domain.
What changes do I do here to redirect my subdomain as well to https 'Secure Connection'.

Looks like there is a problem with your cert installation or signing, that is why it shows "Not Secure".
You may want to try to check if the cert is correctly installed using some checker tool:
Example. https://cryptoreport.websecurity.symantec.com/checker/
Or check with your cert and hosting provider for assistance to see if it is your cert installation or signing problem.

You need to apply/check other .htaccess file(s) in your sub-domain(s) root directories. Example subdomain.yourmaindomain may be located at root/subdomain folder (need be checked - it's depended to your subdomain setting).

Related

.HtAccess rewriting: Direct www.X.com to www.Y.com/test, whilst still showing www.X.com in the browser

I have a domainname, www.X.com that redirects (using some magic from the webhosting-company from which I bought www.X.com) any user that visits www.X.com to www.Y.com/test.
This works fine, but what I would like to happen is for the URL to remain www.X.com after the redirect. Right now, after the redirect the users URL changes to www.Y.com/test.
I'm not sure if htaccess rewriting at www.Y.com can fix this issue, so I would like to know wether this is possible and if so, how do I implement it in my .htacces file?
Regards and thanks in advance,
Robert
Instead of using the redirect tool of your hosting provider. You have to configure your domain to point to your server with a DNS A record:
Domain Type target server
www.X.com. A x.x.x.x
www.Y.com. A x.x.x.x
In your server virtualhost or via your hosting provider you need to configure both domains to point to your website.
In your .htaccess file you need ton configure domain www.X.com to point to the test directory:
RewriteCond %{HTTP_HOST} ^www.X.com$
RewriteRule ^(.*)$ /test/$1
Problem was solved by clearing out my Chrome cache; The webhost-magic HAD done the trick. Thanks mr Rockett and mr Lemaitre for your time!

Apache mod_rewrite condition for hosted domain with SSL

I have five hosted domains with a multi-domain SSL certificate. I cannot write an .htaccess condition that captures both http and https conditions for CNAME www.altdomain.com (a secondary domain). When a user types "https://altdomain.com" in the browser location bar, it shows "connection untrusted" and the URL remains as is. Typing the same with http correctly redirects to https://www.altdomain.com and when the https is omitted, "altdomain.com" is correctly redirected as well.
I am using joomla with a configuration that hides a subdirectory from the URL. The doc root .htaccess file contains this in the custom redirect section:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^altdomain\.com
RewriteRule ^(.*)$ https://www.altdomain.com$1 [R=301,L]
Activating a joomla SSL plugin while omitting custom redirect rules in .htaccess also works, but "https://" with "altdomain.com" fails to redirect in all cases. Perhaps I should have omitted www from the CNAME but there would be a redirect issue there as well if anyone types www in the URL, and I can't change the CNAME without purchasing a new SSL certificate. If there is no .htaccess solution to this problem as I suspect, please explain why.
The standard redirect between www and non-www URLs works only on the primary domain or for http connections. For secure / https connections on secondary domains, there must be an exact CNAME match on the SSL certificate - redirection to a host name that is not listed as a CNAME on the certificate will not work even if the domain name is the same.
If I want https connections to redirect from altdomain.com to www.altdomain.com and vice-versa on a multi-domain SSL certificate, I have to include both CNAMES in the certificate. A five-domain SSL certificate is therefore limited to three domains.

.htaccess rewriting multiple domains on shared hosting ssl

I have a shared hosting on Apache web server with cpanel access to my hosting account
the primary domain abc.in is used to access the public_html folder on which the site files are stored.
I have added a few domains that are not related to abc.com through cpanel add on domains.
They are namely
def.com
ghi.com
jkl.com
so my file system for the domains on shared hosting will be like this
/public_html/ files or directories for abc.in
add on domains are also on
/public_html/def.com/
/public_html/ghi.com/
/public_html/jkl.com/
so you might have understood the working system..
def.com website files are stored in sub directory in public_html folder as shown above
similarly
ghi.com website files are stored in sub directory in public_html folder as shown above
jkl.com website files are stored in sub directory in public_html folder as shown above
now the issue is i need to force https /ssl on primary domain abc.com
the ssl is issued only for abc.in and support.abc.in only
not valid for www version of abc.in and support.abc.in
more over as per my seo knowledge a website should redirect to only one version of website.
that is either www version or non www version
so i have redirection enabled for abc.in in cpanel
so whether it is www.abc.in or abc.in it will go to abc.in only
as discussed earlier ssl is only issued for abc.in and support.abc.in only
now i want to force ssl to entire domain of abc.in and support.abc.in
i have tried cpanel redirection for this,but multiple redirection made a loop and website un accessible.
i have found a .htaccess rewrite here Force HTTPS and strip WWW without receiving Cert error
but enabling it made all the add on domain hosted in sub directories redirecting to abc.in in ssl version.
So i need only ssl access to abc.in and support.abc.in
and i will need separate rules (http) for add on domains and i will be adding more add on domains later.
So i need a htaccess configuration that is generalized for this scenario,so that i can configure the add on domains to use their ssl if needed in future and rules for add on domain that i add in future.
I request the super webmasters and programmers to give some generic/custom generic configuration of htaccess for my situation.
As i am web designer i have no knowledge on htacess rewriting and i am fairly new to this.
Any one who understand the issue,please provide your valuable input.Your response is very important for me.Thank you.
please do explain the code that solves my problem,so that i can customize it later if needed.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(support\.)?abc\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

SSL issue and redirects from https to http

I have a site www.example.com for which i purchased SSL cert and installed.
And it was working fine, I also have a subdomain with app.example.com which was not on SSL.
Both www.example.com and app.example.com are on same IP address.
At later we decided to put SSL only on app.frostbox.com and then i configured SSL with app.frostbox.com and it worked fine,
Now the issue is that Google is indexing my site as https://www.example.com/ and when users hits the web , Invalid security warning is issued and when user allow security issue they are shown my app.example.com contents.
Note: I have my SSL configuration files in /etc/httpd/conf.d/ssl.conf
The contents of the ssl.conf are below.
http://pastebin.com/GCWhpQJq
NOTE: I tried solutions in .httaccess but none of those worked. Like redirecting 301 redirects etc
Purchase a SAN-multi domain certificate. Issue the certificate to www.abc.com and add the additional SAN www.app.abc.com in and it will work.
Hopefully you are within the 30 day cancellation policy.
you need to edit your httpd.conf file or the file where your virtual host is specified and add these lines to redirect http to https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Masking sub domain with a new domain while preserving the paths

I own a domain since long, just masking the names:
http://mydomain.com
Later I started using a subdomain on this domain for some project.
http://subdomain.mydomain.com
Those projects grew and now I have a structure like
http://subdomain.mydomain.com/project1
http://subdomain.mydomain.com/project2
http://subdomain.mydomain.com/project3/subproject1
http://subdomain.mydomain.com/project3/subproject2
http://subdomain.mydomain.com/project3/subproject3
http://subdomain.mydomain.com/project4
....
etc.
now I bought a new domain (shortdomain.com) where I plan not to move anything but everything should be accessible via redirects so everything looks like:
http://shortdomain.com
http://shortdomain.com/project1
http://shortdomain.com/project2
http://shortdomain.com/project3/subproject1
http://shortdomain.com/project3/subproject2
http://shortdomain.com/project3/subproject3
http://shortdomain.com/project4
...
etc.
So basically I need to do two things:
1. if anyone visits my old domain, redirect them the new naming structure. i.e. if someone loads http://subdomain.mydomain.com/project2 they should be redirected to http://shortdomain.com/project2
when a user loads/redirected to http://shortdomain.com/project2 this should actually load the content present at http://subdomain.mydomain.com/project2
So I will not manually migrate projects,codes and GBs of other data. I think this might be acievable by smart redirection only.
Just FYI:
1. I have full DNS control of both the domains
2. I am hosted on hostgator
3. I use cloudflare on the first domain and would like to continue using it
I think this might be acievable by smart redirection only.
No, redirection changes what's in the browser's location bar. If you redirect to shortdomain.com then the request will get sent to shortdomain.com, and have nothing to do with subdomain.mydomain.com anymore. If you redirect back to subdomain.mydomain.com, then the location bar in the browser will change as well.
What you really want to do is point shortdomain.com to the same server and document root that subdomain.mydomain.com is on. Then use this to redirect (either in htaccess file or server config):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://shortdomain.com/$1 [L,R=301]
If, for whatever absurd reason you can't point the shortdomain.com DNS to the same webserver that serves subdomain.mydomain.com, or can't setup that webserver to accept requests for the shortdomain.com host, you need to setup a proxy server. And it'll work something like this:
2 Webservers, server A (hosts subdomain.domain.com) and server B (hosts shortdomain.com)
Someone requests http://subdomain.mydomain.com/project3/subproject1
server A gets the request and redirects the browser to http://shortdomain.com/project3/subproject1
browser's location bar changes to new location
server B gets the request and reverse proxies the request back to server A
server A gets the request again but must recognize that it is a proxy and then serve the page instead of redirecting
As you can see, this is a horrendously ineffecient solution. It's also a high possibility that your hosting service won't allow you to setup proxy servers.
I have full DNS control of both the domains
With full control I assume you can enable mod_proxy as well on Apache web-server of shortdomain.com. Once that is done set it all up this way.
On subdomain.mydomain.com enable mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^ http://shortdomain.com%{REQUEST_URI} [L,R=301]
On shortdomain.com enable mod_proxy, mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shortdomain\.com$ [NC]
RewriteRule ^ http://subdomain.mydomain.com%{REQUEST_URI} [L,P]

Resources