RewriteCond %{HTTP_HOST} ^example\.me [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.me/$1 [R,L]
You’ve not stated where exactly you are adding these rules in your .htaccess
file(s). The order is important. These directives need to go at the top of the .htaccess
file, before the WordPress front-controller, otherwise they won’t redirect anything other than static resources.
This rule will also only redirect example.com
, it won’t canonicalise a request for http://www.example.com/
(ie. HTTP and www) – which is presumably the intention.
To redirect non-www to www and HTTP to HTTPS you would need to include the OR
flag in the first condition it’s either example.com
or HTTP – the default is otherwise an implicit AND. For example:
RewriteCond %{HTTP_HOST} ^example\.me [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.example.me/$1 [R,L]
You also don’t need the <IfModule>
wrapper or to repeat the RewriteEngine On
directive if it is already present later in the file.
Ultimately this should be a 301 (permanent) redirect, so change R
to R=301
once you have confirmed it works as intended.
I have an
.htaccess
file in public_html, which redirects my domain to the specific website folder
I assume you do literally mean a “redirect” and not an internal rewrite? In which case this is OK. However, if you are internally rewriting the request to the specific subdirectory then the above is incorrect as it will expose the subdirectory in the URL. In this case you should remove the rule from the subdirectory .htaccess
file.