Forum Moderators: phranque
[edited by: phranque at 9:33 am (utc) on Mar 30, 2019]
[edit reason] unlinked urls [/edit]
But this gives a 500 error
RewriteCond %{HTTP:X-Forwarded-Proto} =http
in the .htaccess file, I have:
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC,OR]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L] [edited by: phranque at 2:20 pm (utc) on Oct 17, 2019]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
http:// --> https://www.
http://www. --> https://www.
https:// --> https://www.
https://www. --> no redirection [edited by: phranque at 9:58 pm (utc) on Mar 30, 2019]
[edit reason] unlinked urls [/edit]
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
You cannot use %1 when there are OR-delimited conditions, unless every set of conditions has the same capture in the same location. If the first condition is met, there will be nothing to capture. This, by itself, wouldn’t cause a 500 error--but it would in some cases lead to the visitor making an invalid request, which is just as bad. it would still:It is a very, very, very good idea to look at a post after clicking Submit. If what you see is not exactly what you typed, figure out how to change it. (You have, I think, 60 minutes to edit.) Very often it is sufficient to put the troublesome part into [ code ] markup.
do you know the code for a generic redirect please, so that whatever anyone put before actual domain name, it would still:http:// --> https://www.
http://www. --> https://www.
https:// --> https://www.
https://www. --> no redirection
i would try starting with something like this:RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC,OR]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
[edited by: phranque at 2:19 pm (utc) on Oct 17, 2019]