Redirecting HTTP requests to HTTPS
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
4
down vote
favorite
I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS.
There are a lot of tutorials on the Internet, even on Stack Overflow, but some of them seem to be outdated and don't meet good SEO practices.
The scenario is the following one:
- My site has Cloudflare enabled
- My site has a valid SSL on server-side
The current htaccess of my site:
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^MYSITE.cl$
RewriteRule ^(.*) http://www.MYSITE.cl/$1 [R=301]
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
and I want to change .htaccess in order to keep my good SEO rank on Google, use the HTTPS and keep the .WWW:
#OLD PART
RewriteEngine On
RewriteBase /
# Non-www to www (NEW PART)
RewriteCond %HTTP_HOST !^www.
RewriteRule (.*) https://www.%HTTP_HOST/$1 [R=301,L]
# Non-SSL to SSL (NEW PART)
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST/$1 [R=301,L]
#OLD PART AGAIN
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
Will this work like a charm? Do you have a better idea? Does my code have any redundancy? I think that I must set Cloudflare SSL parameters to FULL SSL (STRICT). Is that right?
.htaccess https
add a comment |Â
up vote
4
down vote
favorite
I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS.
There are a lot of tutorials on the Internet, even on Stack Overflow, but some of them seem to be outdated and don't meet good SEO practices.
The scenario is the following one:
- My site has Cloudflare enabled
- My site has a valid SSL on server-side
The current htaccess of my site:
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^MYSITE.cl$
RewriteRule ^(.*) http://www.MYSITE.cl/$1 [R=301]
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
and I want to change .htaccess in order to keep my good SEO rank on Google, use the HTTPS and keep the .WWW:
#OLD PART
RewriteEngine On
RewriteBase /
# Non-www to www (NEW PART)
RewriteCond %HTTP_HOST !^www.
RewriteRule (.*) https://www.%HTTP_HOST/$1 [R=301,L]
# Non-SSL to SSL (NEW PART)
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST/$1 [R=301,L]
#OLD PART AGAIN
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
Will this work like a charm? Do you have a better idea? Does my code have any redundancy? I think that I must set Cloudflare SSL parameters to FULL SSL (STRICT). Is that right?
.htaccess https
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS.
There are a lot of tutorials on the Internet, even on Stack Overflow, but some of them seem to be outdated and don't meet good SEO practices.
The scenario is the following one:
- My site has Cloudflare enabled
- My site has a valid SSL on server-side
The current htaccess of my site:
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^MYSITE.cl$
RewriteRule ^(.*) http://www.MYSITE.cl/$1 [R=301]
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
and I want to change .htaccess in order to keep my good SEO rank on Google, use the HTTPS and keep the .WWW:
#OLD PART
RewriteEngine On
RewriteBase /
# Non-www to www (NEW PART)
RewriteCond %HTTP_HOST !^www.
RewriteRule (.*) https://www.%HTTP_HOST/$1 [R=301,L]
# Non-SSL to SSL (NEW PART)
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST/$1 [R=301,L]
#OLD PART AGAIN
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
Will this work like a charm? Do you have a better idea? Does my code have any redundancy? I think that I must set Cloudflare SSL parameters to FULL SSL (STRICT). Is that right?
.htaccess https
I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS.
There are a lot of tutorials on the Internet, even on Stack Overflow, but some of them seem to be outdated and don't meet good SEO practices.
The scenario is the following one:
- My site has Cloudflare enabled
- My site has a valid SSL on server-side
The current htaccess of my site:
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^MYSITE.cl$
RewriteRule ^(.*) http://www.MYSITE.cl/$1 [R=301]
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
and I want to change .htaccess in order to keep my good SEO rank on Google, use the HTTPS and keep the .WWW:
#OLD PART
RewriteEngine On
RewriteBase /
# Non-www to www (NEW PART)
RewriteCond %HTTP_HOST !^www.
RewriteRule (.*) https://www.%HTTP_HOST/$1 [R=301,L]
# Non-SSL to SSL (NEW PART)
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST/$1 [R=301,L]
#OLD PART AGAIN
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
Will this work like a charm? Do you have a better idea? Does my code have any redundancy? I think that I must set Cloudflare SSL parameters to FULL SSL (STRICT). Is that right?
.htaccess https
edited Apr 18 at 3:11
200_success
123k14142399
123k14142399
asked Apr 18 at 1:23
eplazai
211
211
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04
add a comment |Â
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www
-prefixing rules instead.
However, if you do plan on the FULL SSL feature of cloudflare, you can combine the 2 separate rules into a single one:
RewriteCond %HTTP_HOST !^www. [NC,OR]
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%REQUEST_URI [R=301,L,NE]
Notice that I do not rely on the $1
part of the URI, as matching (and capturing) that is just redundant.
Similarly, the next 2 rules can be combined:
RewriteRule ^/?(do|find)$ /$1.php [L]
You can chose to leave it as $1.php
, but I prefer giving paths from the doc-root in my rules. It is just a personal preference.
Lastly, consider providing some gap between the Options
directive and the directives provided by mod-rewrite
. Again, it is another personal habit of mine; but makes it clearer to maintain large rule sets later on.
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www
-prefixing rules instead.
However, if you do plan on the FULL SSL feature of cloudflare, you can combine the 2 separate rules into a single one:
RewriteCond %HTTP_HOST !^www. [NC,OR]
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%REQUEST_URI [R=301,L,NE]
Notice that I do not rely on the $1
part of the URI, as matching (and capturing) that is just redundant.
Similarly, the next 2 rules can be combined:
RewriteRule ^/?(do|find)$ /$1.php [L]
You can chose to leave it as $1.php
, but I prefer giving paths from the doc-root in my rules. It is just a personal preference.
Lastly, consider providing some gap between the Options
directive and the directives provided by mod-rewrite
. Again, it is another personal habit of mine; but makes it clearer to maintain large rule sets later on.
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
add a comment |Â
up vote
1
down vote
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www
-prefixing rules instead.
However, if you do plan on the FULL SSL feature of cloudflare, you can combine the 2 separate rules into a single one:
RewriteCond %HTTP_HOST !^www. [NC,OR]
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%REQUEST_URI [R=301,L,NE]
Notice that I do not rely on the $1
part of the URI, as matching (and capturing) that is just redundant.
Similarly, the next 2 rules can be combined:
RewriteRule ^/?(do|find)$ /$1.php [L]
You can chose to leave it as $1.php
, but I prefer giving paths from the doc-root in my rules. It is just a personal preference.
Lastly, consider providing some gap between the Options
directive and the directives provided by mod-rewrite
. Again, it is another personal habit of mine; but makes it clearer to maintain large rule sets later on.
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www
-prefixing rules instead.
However, if you do plan on the FULL SSL feature of cloudflare, you can combine the 2 separate rules into a single one:
RewriteCond %HTTP_HOST !^www. [NC,OR]
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%REQUEST_URI [R=301,L,NE]
Notice that I do not rely on the $1
part of the URI, as matching (and capturing) that is just redundant.
Similarly, the next 2 rules can be combined:
RewriteRule ^/?(do|find)$ /$1.php [L]
You can chose to leave it as $1.php
, but I prefer giving paths from the doc-root in my rules. It is just a personal preference.
Lastly, consider providing some gap between the Options
directive and the directives provided by mod-rewrite
. Again, it is another personal habit of mine; but makes it clearer to maintain large rule sets later on.
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www
-prefixing rules instead.
However, if you do plan on the FULL SSL feature of cloudflare, you can combine the 2 separate rules into a single one:
RewriteCond %HTTP_HOST !^www. [NC,OR]
RewriteCond %HTTPS off
RewriteCond %HTTP_HOST ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%REQUEST_URI [R=301,L,NE]
Notice that I do not rely on the $1
part of the URI, as matching (and capturing) that is just redundant.
Similarly, the next 2 rules can be combined:
RewriteRule ^/?(do|find)$ /$1.php [L]
You can chose to leave it as $1.php
, but I prefer giving paths from the doc-root in my rules. It is just a personal preference.
Lastly, consider providing some gap between the Options
directive and the directives provided by mod-rewrite
. Again, it is another personal habit of mine; but makes it clearer to maintain large rule sets later on.
edited Apr 22 at 17:17
answered Apr 22 at 16:53
hjpotter92
4,94611539
4,94611539
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
add a comment |Â
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
@Gerrit0 oh damn! Didn't notice that :/ Fixed now. Thanks :)
â hjpotter92
Apr 22 at 17:17
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f192339%2fredirecting-http-requests-to-https%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
"Will this work like a charm?" Did you try? What's your experience with it so far?
â Mast
Apr 18 at 8:04