WHAT I HAVE
Thanks to this discussion I've solved the problem of the "always https" redirect using this in my .htaccess
:
# Redirect to httpS by default
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect to www if third level domain is not set
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
WHAT I WANT
As per the current configuration, https://example.com
is correctly redirected to https://www.example.com
.
BUT I need that if the URL contains wp-admin
it isn't redirected to www
.
So, for example, https://example.com/wp-admin
hasn't to be redirected.
And also every subpage of the path wp-admin
hasn't to be redirected.
https://example.com/wp-admin/login.php
has to be visible without redirecting to www
but from the second level domain.
CONTEXT (if you are curious about why I need this configuration)
I have the domain example.com
.
This domain has some third level domains and has a Wordpress admin area at example.com
(second level):
example.com
www.example.com
help.example.com
another.example.com
But
www.example.com
is a Symfony app that runs on Heroku;example.com
is a Wordpress multisite installation that runs on DigitalOcean;help.example.com
andanother.example.com
are Wordpress sites handled with the multisite ofexample.com
For these reasons I need to redirect the second level domain to www
if in the path there isn't wp-admin
. In all other cases I need the redirect to www
.