1

I have a website where i want to Force https to all visitors, and I also don't want the URL to show .html at the end.

In Google Search Console and Bing Webmaster tool i get an "Redirect errror" when it tries to index my site.

I'm not sure if my code is good or right. I have made this code in the .htaccess-file:

# Begin
    
RewriteEngine on
    
# Enforce SSL
# Handle non-www URLs
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
# Handle www URLs
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
# Handle URLs without .html extension
RewriteCond %{REQUEST_METHOD} ^(GET) [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
RewriteRule ^(.*) $1.html [L]
    
#Error Codes
ErrorDocument 403 http://example.com/403.html
ErrorDocument 404 http://example.com/404.html
    
# End
4
  • 1
    Is something not working when you deploy this .htaccess? Jan 29 at 11:50
  • I forgot to mention. In Google Search Console and Bing Webmaster tool i get an "Redirect errror" when it tries to index my site. I suspect that the issue is in the .htaccess file. Thank you
    – Simen
    Jan 29 at 12:06
  • What do you get if you test your site yourself? Jan 29 at 15:15
  • What are the details of this "Redirect error"? For what URL(s) are you getting this "Redirect error"? What is the canonical domain? www or non-www?
    – MrWhite
    Jan 30 at 2:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.