.htaccess rewriting multiple domains on shared hosting ssl - .htaccess

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]

Related

Redirect Domain & Sub-domain to HTTPS

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).

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.

Redirect visitor from one domain to another but keep the requested domain name

So I have a client who wants to have a multilingual web site that can be accessed by 2 domain names:
domain_name_1.ru
domain_name_2.ee (default)
The client doesn't want to log in and out every time he/she needs to create content for both sites.
The site itself is running on WordPress and right now the russian version of the site can be viewed by typing in:
domain_name_2.ee/ru
NB! the domain names are hosted at 2 different web hosts.
domain_name_1.ru web hosts only options are 1) to redirect the domain 2) to change name servers
Because of this, I'd like to know if it is possible to run both sites on 1 WordPress install and by using .htaccess can the domain name domain_name_2.ee/ru be masked to domain_name_1.ru when the user visits the site?
The way you want to do this is setup the domain_name_1.ru domain to use the domain_name_2.ee/ru directory as its document root (can do this using virtual host and the DocumentRoot directive). Otherwise you'll have to use mod_proxy, and ensure that it's loaded, and reverse proxy the request to the other domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain_name_1\.ru$ [NC]
RewriteRule ^(.*)$ http://domain_name_2.ee/ru/$1 [L,P]
I managed to redirect and keep domain_name_1.ru in the the address-bar by going to the host and creating an alias for it. Here is a list of my steps:
created an alias for domain_name_1.ru
created a sub domain of ru.domain_name_2.ee
installed WP at htdocs directory
enabled MultiSite
created the MS network
made the necessary MS changes to wp-config and .htaccess files in the htdocs directory
made changes to the name servers by creating a wildcard (*) A/AAA record with redirect to the IP address
created a new site with a domain name of domain_name_1.ru in WP MS.

Using .htaccess to redirect all requests from subdomain to main domain

I have a hobby website for a number of different projects and want each project to have it's own subdomain, like foo.domain.com, bar.domain.com etc.
I use Drupal with the Domain Access module, meaning all subdomains should point to the base installation of Drupal, and then the module recognizes what subdomain the request comes from and serves a page according to that.
Now, since this is just a hobby project, I keep it on a free shared hosting account, which means a few limitations:
No wildcard subdomains.
Each subdomain is linked to a subdirectory with the same name, for example domain.com goes to /public_html/ and sub.domain.com goes to /public_html/sub/ The hosting forces this.
I can't create symlinks.
I have limited space and databases, meaning I can't just make a new installation for each project. (Hence the Domain access module)
My domain registrar (Godaddy) doesn't play nice with shared hosting. I tried hosting the DNS with them and doing a wildcard A record to my hosting server, but it didn't work, and Godaddy don't allow wildcard CNAME records for some reason...
It seems the only option left for me is some .htaccess magic.
I need a .htaccess file to put in the subdomain director(y/ies) to tell apache:
The data is in the root web directory
To not change anything else, so that the Drupal module knows what subdomain was requested and the user still sees "sub.domain.com" in the browser window.
Thankful for your help!
TL;DR
How can I tell Apache to use the data from another directory (i.e. /public_html/ instead of /public_html/subdomain/) WITHOUT making a redirect or any changes to the headers? HTTP_HOST needs to be intact.
Thanks!
Try this:
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301,L]
try this.
RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.example\.com$ [NC]
RewriteRule ^sub/(.*)$ $1 [L]
Not sure if it will work, because I don't know how your host configured to server to map the subdomains to a different folder.
Otherwise you could try the Proxy flag, but that will not set the correct http_host variable in php.
Are you sure Drupal doesn't have a different method of doing multiple installs. I know WP did have a option to use a prefix for all table-names so multiple installs can coexist, using the same database, as long as they use different prefixes. Not sure how big a Drupal install is, and what amount of diskspace your host provides.

how to turn off .HTACCESS rewrite engine off for a file

i have rewrite engine on with a rule to attach www in every url being accessed on my website.
the rule is written in htaccess located in public_html folder. now a problem is i have registered a web application in windows live developer website. as you may know, the windows like applications doesn't accept/allow domains to be verified as www.mydomain.com. they only accept mydomain.com format. so the return url specified in application settings is not delivering data as my verified domain is "mydomain.com" and in return url "www" is being attached due to htaccess rule. so i would like to know if there is any way i can exclude my 1 specific file (not the folder) from all rewrite rules being applied. or is there any way i can verify my domain as www.mydomain.com in windows live applications?
also, is there any way to turn off rewrite rules off for that particular file from PHP?
In your .htaccess rule you can add a condition like this:
RewriteCond %{SCRIPT_FILENAME} !.*myFile.asp$ [NC]
to execute your rewrite rules for everything EXCEPT a file called myFile.asp.

Resources