Apologies in advance. I know this is a old question that keeps getting asked but I haven’t found a solution that works correctly for my needs. I need to direct ALL traffic to reach the non-WWW version of HTTPS website, and I need it to work on multiple domains, not just a single one. example: http//example.com -> https//example.com http//www.example.com -> https//example.com https//www.example.com -> https//example.com http//example2.com -> https//example2.com http//www.example2.com -> https//example2.com https//www.example2.com -> https//example2.com example3, 4 ,5, etc. == Until now I haven’t been using HTTPS, just HTTP. I’ve been redirecting all HTTP requests from non-WWW to WWW. I created an app specifically to redirect: - all non-WWW URLs were added to the redirection_app - all WWW URLs were added to their respective website_app I placed the following rule inside the .htaccess file for the redirection_app: RewriteEngine on RewriteCond %{HTTP_HOST} !^www. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NC] This works fine, but now I want to drop the www and ensure the website is only served over HTTPS: www -> non-www http -> https *.example.com -> https//example.com asked 26 Oct '17, 01:35 wicky |
Hi there! Much like with the WWW-redirects, you'll need one Application to map all your HTTP domains to, which will contain several redirect rules. The .htaccess of the redirect Application will contain two condition-based RewriteRules - one to handle requests from www-domains and one for non-www domains (http://example.com -> https://example.com AND http://www.example.com -> https://example.com):
Note that if you would also like to redirect HTTPS requests from www-domains to their non-www versions (https://www.example.com -> https://example.com), you will need another redirection Application to handle all HTTPS requests to www-domains. It will have a different set of rules in its .htaccess file:
You would only map the www-versions of the domains to this HTTPS redirect Application, again if you wish to redirect HTTPS requests of www-domains to their non-www counterparts, which will of course be mapped to the actual Applications serving the appropriate content. Finally, I would like to say that some CMS systems such as Wordpress, with which you can set the preferred URL parameter for a specific website will not require the additional redirect Application, since they provide permalink redirects of their own through PHP. Namely, if you have a Wordpress instance with its home and siteurl parameters set to the non-www version of the domain, Wordpress will perform the redirect after the HTTPS redirect takes place. answered 26 Oct '17, 08:21 hristod ♦♦ Thank you for the help @hristod, it’s much appreciated! The first part works perfectly. Both HTTP requests (www AND non-www) redirect to HTTPS non-www. However the 2nd redirection app for HTTPS gives an insecure website notice when I test https://www.example.com. I have valid certificates for each site (both www and non-www), but I can’t apply multiple certificates to a generic app that handles multiple domains. Is there a way around this? I know I could apply the 2nd .htaccess content to each individual application’s .htaccess , but the HTTPS redirection app is much more preferable.
(26 Oct '17, 18:38)
wicky
@wicky no, there is no way around that. If you need to use multilple certificates, then you'll have to use multiple sites.
(26 Oct '17, 18:45)
seanf
|