: How to redirect all (www).example.(com/net/org) to https://example.com How do I setup any URL/URI for http(s)://(www).example.(com/net/org)/somepath to end up at the corresponding: https://example.com/somepath
How do I setup any URL/URI for
http(s)://(www).example.(com/net/org)/somepath
to end up at the corresponding:
example.com/somepath
I'm guessing that the solution (if there is one), will involve DNS settings and .htaccess voodoo. But I don't really understand how those things work (particularly .htaccess). So, some specific suggestions on what to read would also be appreciated. (Yes, I can google, but this seems to be a rather specific and/or esoteric question, and I have been unsuccessful in effecting a solution. Or, I could be stupid...)
Setup:
I have domains example.net/.org/.com all registered with the same registrar. Via the registrar's domain settings, I have example.net and .org setup to redirect (301) to example.com. I have example.com hosted at a separate shared hosting company that uses Apache & cPanel.
Currently, some redirects work: (with or without www).example.(net/org) => example.com.
However, www.example.com does not redirect to just example.com.
Now for the tricky part. The web host also has "SNI based SSL". So, exmple.com and www.example.com both work, but, with https, the www URL does not redirect to the base domain (https://example.com).
Additionally, example.net does not work either, with or without the www (won't connect/times out).
So, in short (too late??), if possible, how do I configure all permutations of the above to end up at the corresponding:
example.com/somepath
Or, if the answer would require the completion of a doctoral thesis to implement, what is a common/reasonable setup?
More posts by @Margaret670
1 Comments
Sorted by latest first Latest Oldest Best
Additionally, example.net does not work either, with or without the www (won't connect/times out).
For .net and .org to work on HTTPS you need to have SSL certs that cover these domains (as you do already for the .com) - "SNI based SSL" is fine. However, in order to do this, you probably need to have the DNS for these domains pointing to the same server (your hosting account) and these domains configured as "Alias" (or "Parked") domains within your cPanel account. ie. Change the NAMESERVERS on these domains at your registrar, the same you have probably done for example.com. (That is unless your domain registrar can configure SSL for these domains and you can configure the appropriate redirect from that end - which I very much doubt.)
You can then issue ("Let's Encrypt"?) SSL certs that cover these additional domain names within cPanel.
Currently, you have redirects for .net and .org from your registrar, because the DNS is currently handled by your registrar. When you point the DNS to your webhost these redirects will naturally stop working.
And now for the .htaccess "voodoo" to redirect everything to your canonical host (example.com) and HTTPS. Actually, it's really not that bad, as far as redirects go.
At the top of the .htaccess file in the document root, add the following mod_rewrite directives:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^ example.com%{REQUEST_URI} [R=302,L]
The above states... if the requested Host is not example.com (the canonical host) or the request is not HTTPS (the desired scheme) then redirect to example.com/somepath.
Note, the above is a 302 (temporary) redirect. Change this to a 301 (permanent) only when you have confirmed it is working OK. 301s are cached hard by the browser (by default) so can make testing problematic.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.