https redirects + Cloudflare Page Rules missing situation

https redirects + Cloudflare Page Rules missing situation - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the https redirects + Cloudflare Page Rules missing situation error on your web browser. Problem :


I have just moved my website to https and after some scares it is working, mostly.



I did find out that when I input the naked domain on the browser it is not going to the desired URL, as follows:




  • typed URL = example.com

  • redirects to = https://example.com

  • desired URL = https://www.example.com



The following Page Rule is set on Cloudflare:




  • pattern = http://*example.com/*

  • rule = Forwarding to https://www.example.com/$2



On the origin server, the .htaccess file has:



RewriteCond %HTTPS off

RewriteRule (.*) https://%HTTP_HOST%REQUEST_URI [R=301,L]


What am I missing?


Solution :

%HTTP_HOST will refer to whatever host the site was accessed through. ie. example.com or www.example.com. To always redirect to www.example.com then simply put this in the substitution:



RewriteCond %HTTPS off
RewriteRule .* https://www.example.com%REQUEST_URI [R=301,L]


But unless you had a similar rule before then both example.com and www.example.com would have been accessible (and possibly indexed). In fact, if you access https://example.com now it does not redirect to https://www.example.com. You also need the following, in addition to the above:



RewriteCond %HTTP_HOST !www.
RewriteRule .* https://www.%HTTP_HOST%REQUEST_URI [R=301,L]


So, in summary, the first block corrects for HTTP -> HTTPS and the second corrects if the www subdomain is omitted. I also removed the parentheses in your pattern (.*) since you aren't capturing it for the substitution.



These two rule blocks could be combined into one if desired...



RewriteCond %HTTPS off [OR]
RewriteCond %HTTP_HOST !www.
RewriteRule .* https://www.example.com%REQUEST_URI [R=301,L]

We hope that this article has helped you resolve the redirects, https, cloudflare error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=