Would like to do the following on my website using .htaccess rewrite mod:
- redirect users without https://* to https://*
- redirect users with www.example.com to example.com
- rewrite example.com/index.htm to example.com/home
- redirect every URI to index.htm exept of /home, /background.jpg, /icon.png and /fonts/segoeui.ttf
This is the code I already have:
RewriteEngine On
RewriteBase /
RewriteRule ^\.htaccess$ - [F]
# --- Part that looks stupid but is working ---
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# --- Part that is not really working ---
RewriteCond %{REQUEST_URI} !^/(index\.htm)?$ [NC]
RewriteRule ^.*$ /index.htm [L,R=301]
So, is there a better way to combine the https and the www thing? It is more a copy and paste solution than good code. I have not much knowledge with this.
The redirection to index.htm is working, but how can I prevent /background.jpg, /icon.png and /fonts/segoeui.ttf from being redirected too? And what about rewriting the whole thing to /home?
Thanks for your help!