Then later when I tried to edit the .htaccess code there were no any rule I previously added. But the redirect still worked as it should.
301 redirects are cached hard by the browser, so if the redirects are no longer in the
.htaccess file (or moved to the server config) then it's quite possible you are seeing a cached response. Clear your browser cache and retest.
Do you have HTTP Strict Transport Security (HSTS) enabled on your domain? If yes, then after the initial HTTPS request the browser will always (or rather, for a specified period of time) request the HTTPS version automatically. This will also not require the redirect directive (after the initial request), but new users will not be redirected, until they have first visited the HTTPS version.
It's also possible that your server-side code (CMS / WordPress?) is performing this canonicalisation and redirecting to your canonical URL. At the end of the day you need a "redirect" somewhere in your code for the site to redirect, this doesn't happen by magic.
- Is this normal?
Directives "disappearing" from
.htaccess is not normal. Although it's possible that updates to your CMS (eg. WordPress??) could have overwritten these. (?)
- I didn't use
<IfModule mod_rewrite.c> tags when adding the code. Is it okay or should I add those opening and closing tags and add it again?
You don't need the
<IfModule> wrapper. In fact, it is probably better to not have it. The
<IfModule mod_rewrite.c> wrapper is only required if your site is intended to function "normally" without mod_rewrite or you have other modules that are dependent on mod_rewrite.
Note that if you are using WordPress... WordPress uses the
<IfModule> wrapper because it is designed for maximum compatibility and can function without mod_rewrite being installed. But if mod_rewite is not available then you lose some URL formatting capability.
- If you have a better way to do the redirect...
This redirect looks good. The only reason to change it would be if it's not working. (eg. You started serving HTTP from a different port or something?) The only improvement would be to use your server config instead and disable