Redirect www.example.com to https://example.com (without www)

Hello community,

I have one issue with redirecting w w w. m i l e m i j a t o v i c . c o m to h t t p s : / / m i l e m i j a t o v i c.c o m, however when I want to access to my site without www , it’s properly redirected to the
h t t p s : / / m i l e m i j a t o v i c .c o m

DNS and HTTP Proxy (CDN) is turned on for “A” which is my domain m i l e m i j a t o v i c .c o m and “CNAME” which is www - Value is an alias of m i l e m i j a t o v i c .c o m

SSL - milemijatovic.co m, *.milemijatovic.co m (2 hosts) Universal (Shared)

Always use HTTPS - Turned on
Automatic HTTPS Rewrites - Turned on

Can you help me how to fix this little issue? Do I need to add new page rule or … ?

Sorry I wrote .co m because I can not use more than two links as new user. Thank you

Works perfectly for me. Both http://milemijatovic.com and http://www.milemijatovic.com redirect to their https equivalents.

Thank you for your reply… but it is an issue when you enter www.milemijatovic.com, should be redirected to the https://milemijatovic.com without www

How to fix that? Can you help me?

It does work properly (for me). “www” gets stripped off when I use HTTP or HTTPS. All combinations ultimately lead me to https without the www.

Yes, everything is ok now.

I solve with this line of code in .htaccess file

RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*) [NC] RewriteRule ^(.*) http://%1/$1 [R=301,L]

2 Likes

I would change the RewriteRule to point to https instead of the default http. It’ll strip the www and redirect to https all in one swoop.

Ok, thank you for suggestion , can you tell me how to do that? I currently have issue with google analytics, I am not sure does it affects the fact that the google analyst does not show any visitors in real time?

Edit that line of code in .htacess to change the http:// so it says https://
Use whatever editor you just used when you added that line.

Ah, Google Analytics. Is it set up for the www domain? I don’t use Google Analytics, but as I recall from their Webmaster Tools, you need to specify if it’s a www or non-www domain you’re analyzing. Looking at my webmaster tools console, my sites are configured as https.

So…log into Google and make sure you’re using https and not using www.

Ok, I changed http:// to https:// in .htaccess. Thanks for the advice.

In google analytics, no, its not www, I use https://milemijatovic.com

I am not sure why real time overview is not displayed :confused:

How about trying the new Google Analytics app here at Cloudflare? You’ll have to turn off your site’s current Analytics code so it doesn’t double-count or conflict.

Just a moment. For some reason, my google analytics now works properly :slight_smile:

Thanks

1 Like

@sdayman isn’t it more efficient to do 301 redirects with a Page Rule instead of .htaccess? Like this: