If I add that after the existing redirect, it appears to not have any effect.
Yes, that is correct. mod_rewrite directives execute top-down (in any given context). The existing directives implement a front-controller type pattern and consequently rewrite most requests to index.php
. If the request is rewritten then any directives that follow (ie. your redirect) are simply never processed. (However, change your request to something like /foo/bar.css
- regardless of whether this file exists or not - and the redirect should still be triggered.)
If I add it just after the RewriteBase / Firefox gives me the message:
Yes, the HTTP to HTTPS redirect should be placed at the top of your file. After the RewriteBase
directive is a logical place to put it.
The page isn't redirecting properly
In other words, you are seeing a redirect-loop. With the directive you've given, that uses the HTTPS
server variable, this error implies your host has implemented SSL with some kind of front-end proxy and traffic from the front-end proxy to your site is probably plain-old HTTP (ie. unencrypted).
You need to clarify with your webhost that this is the case and they should be able to tell you exactly what directive(s) you should be using. This might be specific to your server config.
Some hosts set an HTTPS
environment variable (yes, same name, but different variable) when the request comes in over HTTPS. This is accessed like %{ENV:HTTPS}
(as opposed to %{HTTPS}
). This is reasonably common, but is server specific.
A standard proxy server will set the X-Forwarded-Proto
HTTP request header in the forwarded request to your application server. So, you can perform the required HTTP to HTTPS redirect with something like the following instead:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.example.com/$1 [R=301,L,NE]
However, you must clarify with your webhost that this is indeed how the SSL is implemented before using something like this in production. Otherwise, if your site is not behind a (SSL) proxy server then it's possible for someone to construct a malicious request and prevent the site from redirecting to HTTPS.
Since you are messing with 301 (permanent) redirects, you must clear your browser cache before testing.
If I add that after the existing redirect, it appears to not have any effect.
Yes, that is correct. mod_rewrite directives execute top-down (in any given context). The existing directives implement a front-controller type pattern and consequently rewrite most requests to index.php
. If the request is rewritten then any directives that follow (ie. your redirect) are simply never processed. (However, change your request to something like /foo/bar.css
- regardless of whether this file exists or not - and the redirect should still be triggered.)
If I add it just after the RewriteBase / Firefox gives me the message:
Yes, the HTTP to HTTPS redirect should be placed at the top of your file. After the RewriteBase
directive is a logical place to put it.
The page isn't redirecting properly
In other words, you are seeing a redirect-loop. With the directive you've given, that uses the HTTPS
server variable, this error implies your host has implemented SSL with some kind of front-end proxy and traffic from the front-end proxy to your site is plain-old HTTP (ie. unencrypted).
You need to clarify with your webhost that this is the case and they should be able to tell you exactly what directive(s) you should be using. This might be specific to your server config.
Some hosts set an HTTPS
environment variable (yes, same name, but different variable) when the request comes in over HTTPS. This is accessed like %{ENV:HTTPS}
(as opposed to %{HTTPS}
). This is reasonably common, but is server specific.
A standard proxy server will set the X-Forwarded-Proto
HTTP request header in the forwarded request to your application server. So, you can perform the required HTTP to HTTPS redirect with something like the following:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.example.com/$1 [R=301,L,NE]
However, you must clarify with your webhost that this is indeed how the SSL is implemented before using something like this in production. Otherwise, if your site is not behind a (SSL) proxy server then it's possible for someone to construct a malicious request and prevent the site from redirecting to HTTPS.
Since you are messing with 301 (permanent) redirects, you must clear your browser cache before testing.
If I add that after the existing redirect, it appears to not have any effect.
Yes, that is correct. mod_rewrite directives execute top-down (in any given context). The existing directives implement a front-controller type pattern and consequently rewrite most requests to index.php
. If the request is rewritten then any directives that follow (ie. your redirect) are simply never processed. (However, change your request to something like /foo/bar.css
- regardless of whether this file exists or not - and the redirect should still be triggered.)
If I add it just after the RewriteBase / Firefox gives me the message:
Yes, the HTTP to HTTPS redirect should be placed at the top of your file. After the RewriteBase
directive is a logical place to put it.
The page isn't redirecting properly
In other words, you are seeing a redirect-loop. With the directive you've given, that uses the HTTPS
server variable, this error implies your host has implemented SSL with some kind of front-end proxy and traffic from the front-end proxy to your site is probably plain-old HTTP (ie. unencrypted).
You need to clarify with your webhost that this is the case and they should be able to tell you exactly what directive(s) you should be using. This might be specific to your server config.
Some hosts set an HTTPS
environment variable (yes, same name, but different variable) when the request comes in over HTTPS. This is accessed like %{ENV:HTTPS}
(as opposed to %{HTTPS}
). This is reasonably common, but is server specific.
A standard proxy server will set the X-Forwarded-Proto
HTTP request header in the forwarded request to your application server. So, you can perform the required HTTP to HTTPS redirect with something like the following instead:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.example.com/$1 [R=301,L,NE]
However, you must clarify with your webhost that this is indeed how the SSL is implemented before using something like this in production. Otherwise, if your site is not behind a (SSL) proxy server then it's possible for someone to construct a malicious request and prevent the site from redirecting to HTTPS.
Since you are messing with 301 (permanent) redirects, you must clear your browser cache before testing.