All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
.htaccess redirect help
Yes, I've googled, found different solutions/advice, so though to ask here. I thought it is a routine ruleset to be implemented. But posting the question on another forum (WHT) didn't provide any help. Anyway:
For WordPress websites (if that is relevant) I'd like to use .htaccess rules to enforce the following redirections:
1)
Main domain:
All visits to either:
http://www.example.com
http://example.com
https://example.com
should be redirected to:
https://www.example.com
Including any "trailing" stuff, of course, like:
http://www.example.com/about/ to https://www.example.com/about/
2)
Sub-domain (placed on a separate cPanel account if that info is important)
All visits to either:
http://sub.example.com
http://www.sub.example.com
should be redirected to:
https://sub.example.com
Also including any "trailing" path additions.
Comments
If both websites are using CMS like wordpress then you don't need .htaccess rules to do that.
Just modify your website url settings. And it will works perfectly..
If you still needs to redirect then follow this
https://in.godaddy.com/help/redirect-http-to-https-for-wordpress-on-linux-27904
https://wordpress.org/plugins/https-redirection/
Note: if you are using cPanel then there's option to set redirection rules..
It can be found under the domains>Redirects
It will modify your htaccess automatically
It doesn't work with old links for example:
http://www.sub.example.com/about/
doesn't work, not getting redirected to
https://sub.example.com/about/
Use this
https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/
Thanks. Just to confirm, for the subdomain:
`
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC]
RewriteRule ^(.)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
`
Will this redirect:
http://sub.example.com
http://www.sub.example.com
https://www.sub.example.com
to
https://sub.example.com
?
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Follow this steps as FoxelVox suggested
Worked like a charm.
Thank you very much.
The version I quoted in the previous post - tested for a subdomain. Using 302 of course.
It doesn't work only for https://www.sub.example.com/ - but there are no old links using that "structure".
I suspect SSL/TLS certs not "covering" ..example.com, but only *.example.com to be causing that.
Since, from what I can read from the code, it should redirect that as well.
you should combine the rules into one to avoid multiple redirects.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteRule ^ https://sub.example.com%{REQUEST_URI} [L,NE,R=301]
Not disputing, just asking.
This setup, from what I could test (browser, f12, network, then check the redirects), did only one redirect for any test link I have tried:
`RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC]
RewriteRule ^(.)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]`
It always made one redirect to the desired, "naked" subdomain version/address.
Again, the test method used was from the browser. No cache, cookies - just looking at the network info.
true story. I have to admit I just glanced at it and did not check in detail. you are right, that combination of the two rules in that order should take care without a double redirect ;-)
Use it:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule .* http://example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]
Learn Regular Expressions. It is a great skill to have. The syntax may seem daunting but only takes a few hours to learn. Having a cheat sheet handy helps too.