I need help setting up the .htaccess for my DigitalOcean App Static Website

Posted December 8, 2020 1.9k views
DigitalOceanHTMLDigitalOcean App PlatformBuilding on DigitalOcean

I created my static website with the new service called Apps, and I tried to add my .htaccess file, so the file gets uploaded and can be accessed by url through URL but is not working on Digital Ocean and it’s not being executed.

I wonder what is the problem?

The .httaccess contains this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
ErrorDocument 404
ErrorDocument 500
RewriteCond %{HTTPS} !on 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi Akaben,

Static Sites on App Platform are not served by an apache server, so an .htaccess file will have no effect. What are you trying to accomplish with that configuration? We can help you find out if it’s possible with App Platform today and if so, help you achieve it.

  • Hi meskinazi,

    Thanks for the answer, what I want to do is remove .html from url and force www and non https www to https non www.

    • Today we force HTTPS for all apps by redirecting requests to the non secure url to the secure one using 301 redirects.

      We don’t support redirecting domains for static sites, but you can add both www and non-www domains to your app and they would be served from both URLs. As of rewriting URLs to hide the .html extension we can hide index.html when accessing a path so if you put each file inside a directory with the url you want and an index.html inside it should work, for example:

      /bio.html -> /bio/index.html
      /about-us.html -> /about-us/index.html

      Then you’d be able to access /bio and /about-us with prettier URLs.

      In any case, I’ve noted your request to support redirects and URL rewrites and we’ll explore what we can do about it in the future.

      • Redirecting from www to non-www is definitely a must have feature, as having both can result in a duplicate content penalty from google ranks and is bad for SEO.

        I am looking forward on your solution for this :)

      • Had similar issues as the other peeps with Sitechecker + Lighthouse suggesting that the HTTPS redirect wasn’t working, not sure why as in dev tools I could see the 301 taking place.

        I have since fronted my app with Cloudflare which seems to sort that issue and has the added benefit of helping out with cacheing/performance.

        The above tools still complain about the .html extension even though they are not even available, so also interested in what you come up with on that one.

Is there any update on this question? I cannot redirect my hugo website hosted by digitalocean app, from www to non-www.