.htaccess alternative for www redirect?


Years ago, I set up .htaccess rules for www/non-www versions of my website. As I transfer it to DigitalOcean, I want to make sure I don’t incur any SEO penalties for a change in this configuration.

Could someone please tell me how to apply the following rules to my DigitalOcean App? Note that I’m not using Apache (because it’s just an App in the DigitalOcean console), so I can’t simply copy the .htaccess file.

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^!www\.example\.com [NC]
    RewriteRule ^(.*)$$1 [R=301,L]
    RewriteCond %{HTTP_HOST} ^ [NC]
    RewriteRule ^(.*)$$1 [R=301,L]
    RewriteCond %{REQUEST_URI} ^/example($|/.*$)
    RewriteRule ^.* [R=301,L]
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I’m not an .htaccess expert, so please let me know if there are errors I should account for. My primary goal is to make my migration invisible to search engines in this regard.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Hi @JustAnotherUser,

As far as I know, at this point in time, It is not possible to add URL rewrites to the App platform. But you can post this idea on the below link:

Additionally, you can try using one of the Droplets provided by DigitalOcean, they are like any other server/droplet which you can customize and install whatever you want on them.

This comment has been deleted