1

Currently my .htaccess looks like this and works perfect for http. It redirects to www. and removes the .html file extension.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

I have tried the .htaccess from this answer but still the site in question is completely messed up. E.g https://example.com/work shows a 404. Also all images that are linked in the source code with /img/example-01.jpg do not show.

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Can you please help me with getting a .htaccess file that:
1.
Redirects to https
2.
Redirects to www. subdomain
3.
Removes .html from file extension so that example.com/work shows the work.html page.

Thank you for your help.

lowtechsun
  • 1,915
  • 5
  • 27
  • 55

1 Answers1

0

If your current .htaccess works fine, this modification should do:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{REQUEST_SCHEME} !https
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Dusan Bajic
  • 10,249
  • 3
  • 33
  • 43
  • Nope, ´https://www.example.com/work´ result in 404, same as ´https://www.example.com/img/desktop/1.jpg´. This is the Let's Encrypt certificate. Contacted the host already. The site is super simple with static content. – lowtechsun Dec 10 '16 at 14:37
  • Does `https://www.example.com/img/desktop/1.jpg` work if you completely remove .htaccesss? – Dusan Bajic Dec 10 '16 at 16:06
  • Just checked and no, does not work. To be precise, since there is no redirect to www. with the removed .htaccess the URL ´https://example.com/img/desktop/1.jpg´ does not work. – lowtechsun Dec 10 '16 at 16:34
  • No. But you are right for asking a 2nd time!! `https://www.example.com/img/desktop/1.jpg` does not work, **however** `www.` seems to be in place since `http://www.example.com/img/desktop/1.jpg` works without any `.htaccess` present in the directory for the site. – lowtechsun Dec 10 '16 at 16:40
  • Well, If you want the rewrite from `http://example.com/img/desktop/1.jpg` to `https://www.example.com/img/desktop/1.jpg` to return something other than 404. you first have to make `https://www.example.com/img/desktop/1.jpg` (when entered like that directly in address bar) work, which is unrelated with .htaccess – Dusan Bajic Dec 10 '16 at 16:46
  • Got your point. Thank you. In touch with the host now and asking why despite having removed the `.htaccess` completely `https://www.example.com/img/desktop/1.jpg` does not work. Very good point in fact, thank you. – lowtechsun Dec 10 '16 at 16:51