Redirect all 404 to 301 (.htaccess)

This is the simple code that I use to redirect all 404 errors (Not Found) to 301 (Moved Permanently). This will help you a lot if you had a previously WordPress site or another popular CMS that used a lot of permalinks to display content (eg.: tags, categories etc.).

This will also help with Google Search Console not found errors. After a new Google Crawl Index it will show a clean domain with no 404’s.

Hope it helps…

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]

Force https and activate mod_deflate

This is my .htaccess file that manages the https and gzip compression(server side).

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
</IfModule>