I need to:
-
add www, so user will:
- type
https://example.com/test.html
- see in browser
https://www.example.com/test.html
- get file from
example.com/test.html
- type
-
add http -> https redirect, so user will:
- type
http://www.example.com/test.html
- see in browser
https://www.example.com/test.html
- get file from
example.com/test.html
- type
-
add subdomain silent redirect, so user will:
- type
https://new.example.com/test.html
- see in browser
https://new.example.com/test.html
- get file from
example.com/new/test.html
- type
-
and of course combinated, for example:
- type
http://new.example.com/test.html
- see in browser
https://new.example.com/test.html
- get file from
example.com/new/test.html
- type
Is this possible via .htaccess file, eventually how?
www and https forwarding is already working fine for me, but I do not know, how to do silent forwaring with subdomains:
RewriteEngine On
# https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# WWW
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} !^new. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Thank you.
2
Answers
With your shown attempts/samples, could you please try following. Please make sure to you your htaccess rules in following way and clear your browser cache before testing your URLs.
You may try these rules in site root .htaccess:
Make sure you don’t have any other code except these lines in site root and you must clear browser cache completely.