Хостинг в Україні від Mevcore

.htaccess generator

HTTPS, www, redirects, caching, compression, security headers and IP blocking — a ready .htaccess in a minute.

Basics
Speed and security

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect to HTTPS
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Without www: www.example.com → example.com
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]
</IfModule>

# Don’t list files in directories without an index file
Options -Indexes

# Deny access to service files
<FilesMatch "^(\.env|\.git.*|\.htpasswd|composer\.(json|lock)|.*\.(bak|sql|log|ini|sh))$">
    Require all denied
</FilesMatch>

# Response compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/json application/javascript text/javascript image/svg+xml
</IfModule>

# Browser caching for static files
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
Download

Save it as .htaccess in your site’s root directory (public_html). Before replacing the file, back up the old one and check the result in the validator.

What is .htaccess

.htaccess is a per-directory configuration file for the Apache web server. It lets you set up redirects, protection, caching and compression without access to the server configuration. The rules apply to the directory containing the file and all its subdirectories.

Tips

  • HTTPS and www — pick one main address for your site and redirect all the others to it, so search engines won’t treat the site as duplicate content.
  • Caching and compression make pages load several times faster and improve your Google PageSpeed score.
  • HSTS should only be enabled once the SSL certificate definitely works on all subdomains: browsers remember this setting for a year.
  • If the site shows a 500 error after a change, restore the previous file and check the syntax.

The generator produces Apache 2.4 rules that work on MEVCORE shared hosting.

What should we call you?

Enter your name before starting the chat.

Hello! Type your question and an agent will reply as soon as possible.
Rate the agent’s reply