I want to redirect http to https and www to non www.
Cases:
http://example.com/my/url
http://www.example.com/my/url
https://example.com/my/url
https://www.example.com/my/url
Result
https://example.com/my/url
https://example.com/my/url
https://example.com/my/url
https://example.com/my/url
My current htaccess file:
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
Problem:
It redirects to https://example.com/index.php.
I want it to respect the url https://example.com/my/url.
I've found many questions but I have not yet found a complete solution. In fact, the htaccess code above was the only one that worked quite well out of like 10 tries.