Forum Moderators: phranque

Message Too Old, No Replies

cloudflare 301 permanent redirect url

         

anthonyinit

7:03 am on Jan 23, 2021 (gmt 0)

10+ Year Member



Hello All,

I'm using Nginx and i want to send my desired URL type with www. from the script i have setup my url to be www. now the question is how i can add rewrite code in nginx? so for that i used cloudflare page rule and set it to be as follow

http://example.com/*
https://www.example.com/$


that did the trick and now my website using www. however, i have a small issue with the url. my website url is now
https://www.example.com/$


so i went back to cloudflare and in the page rules i removed the
/$
from
https://www.example.com/$
after doing that i don't see anymore /$ when i visit my website is it now showing
https://www.example.com


but i'm not sure removing
/$ 
is the right thing to do?

Please advice

phranque

8:01 am on Jan 23, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i think you want all pages to redirect, not just the home page.
try this for "If the URL matches":
http://example.com/*

and then try this for "Enter Destination URL":
https://www.example.com/$1

make sure you use a 301 redirect for this and clear any relevant cache before testing changes.
you may need additional rules for other noncanonical hostnames.
for example each of the following should redirect to https://www.example.com/
http://example.com/
http://www.example.com/
https://example.com/

and any of those hostnames with a url path specified should redirect to https://www.example.com/path/to-url

anthonyinit

6:41 pm on Jan 23, 2021 (gmt 0)

10+ Year Member



@phranque That did the trick. I add
/$1
https://www.example.com/$1
and it worked.

now my url showing like this
https://www.example.com


Thank you so much for your support :)