GS
genstack.tools
Apache & Nginx Web Server Rules

Free .htaccess & Nginx 301 Redirect Generator

Generate clean, SEO-safe rewrite rules and 301 permanent redirects for Apache (.htaccess) and Nginx. Enforce HTTPS, handle canonical WWW redirects, and block unauthorized crawlers.

Advertisement
Sponsored Space

SSL & Canonical Rules

Security & Performance

Custom Page-to-Page Redirects

Advertisement
Sponsored Space
.htaccess (apache)
# ============================================================
# Apache .htaccess Configuration File
# Generated by GenStack Web & Server Generator
# ============================================================

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # 1. Force HTTPS (SSL)
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # 2. Redirect WWW to Non-WWW
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

  # 4. Block Aggressive Web Scrapers
  RewriteCond %{HTTP_USER_AGENT} (GPTBot|CCBot|Bytespider|ClaudeBot|Amazonbot) [NC]
  RewriteRule .* - [F,L]

  # 5. Custom 301 / 302 Path Redirects
  Redirect 301 /old-page /new-page
  Redirect 301 /blog/post-1 /articles/post-1
</IfModule>

# Prevent Directory Indexing
Options -Indexes

# Custom Error Documents
ErrorDocument 404 /404.html

# Enable Browser Caching & Gzip Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
</IfModule>