Report this

What is the reason for this report?

.htaccess alternative for www redirect?

Posted on January 10, 2022

Hello,

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 ^(.*)$ http://www.example.com/$1 [R=301,L]
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    RewriteCond %{REQUEST_URI} ^/example($|/.*$)
    RewriteRule ^.* http://www.example.com%1 [R=301,L]
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

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.

Thanks!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.