A better way to redirect https and non www traffic - SOLVED


#1

Hi,

Attempting to minimize redirects on our sites. For example, a browser user enters:
“rosemariespeaks ‘dot’ com”

{{SORRY, HAVE TO USE ‘dot’ instead of . - system thinks I’m a spammer.}}

I want to redirect to www ‘dot’ rosemariespeaks ‘dot’ com AND force the use of SSL.

In the example below (nginx), I’m able to do this successfully. However, its a couple of redirects.

Wondering if this logic can be performed at the dns level (ie CF), and how would I go about implementing it. Thanks for your suggestions.

==============
server {
if ($host = www ‘dot’ rosemariespeaks ‘dot’ com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = rosemariespeaks 'dot' com) {
    return 301 https://www 'dot' rosemariespeaks 'dot' com$request_uri;
} # managed by Certbot

listen 80;
server_name rosemariespeaks 'dot' com www 'dot' rosemariespeaks 'dot' com;

}

include /etc/nginx/301s/rosemariespeaks.map;

server {
listen 443 ssl http2;

# this line is the logic for the included map
include /etc/nginx/301s/map.conf;

server_name rosemariespeaks 'dot' com www 'dot' rosemariespeaks 'dot' com;

#... more code...

}


#2

It’s simply the Always Use HTTPS option in the dashboard and a Page Rule to redirect from naked domain to www (without specifying http:// or https://).


#3

I did as you prescribed, page rule 301 redirection. Cleared cache on the browsers. Removed the nginx 80 server block, reloaded nginx.
Pages can’t be found.


#4

Have you set SSL to Full or, better, Full (Strict)?


#5

SSL is full, LE cert has been on the site. Set https always. Just changed SSL to strict.


#6

It isn’t resolving on Cloudflare for me though. Are the naked domain and www on :orange:?


#7

I’ll reinsert the correct nginx and restart, one moment.


#8

OK, nginx server block changed and nginx restarted.


#9

The website loads for me, HTTP and HTTPS, but it isn’t passing through Cloudflare…


#10

cf is on now for www and non www.


#11

See if this rule is correct, in image. Then I will enable.


#12

You need to add a * at the end of the match and a $1 at the end of the redirect, removing the final /.


#13

did that and turned on the rule.


#14

Seems to be working correctly, even after clearing the cache.
Tried both ‘rosemariespeaks.com’ and ‘www.rosemariespeaks.com


#15

Current response

http://rosemariespeaks.com/aa
Location: https://www.rosemariespeaks.comaa

for the forwarding URL, you will need a slash before the $1, like /$1, so https://www.rosemariespeaks.com/$1.


#16

Good catch, thanks for jumping in and helping out.


#17

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.