Set up HTTP 301 redirects via .htaccess

In this help center article you will learn how to set up HTTP 301 redirects for your server using the Apache2 mod_rewrite extension and the .htaccess file.

General setup

A .htaccess file is required in your document root (root directory) to set up mod_rewrite rules. If no file has been created yet, please create an .htaccess file with the following content:

RewriteEngine On

Tip: Structure your mod_rewrite rules to avoid multiple 301 redirects. Example: Instead of http://domain.dehttps://domain.de, you should immediately redirect from to

Forwarding of individual URLs

To redirect specific URLs, please use the following scheme:

Redirect 301 /old-product-detail-page/

Example: 301 →

Forwarding of individual directories

To forward entire directories including the existing subdirectories, please use the following rule:

RewriteRule ^old-product-category/(.*)$ /new-product-category/$1 [R=301,NC,L]

Forwarding to www. subdomain

Please use the following rule to redirect all pages that are not accessed via the www. subdomain:

RewriteCond %{HTTP_HOST} ^www\.domain\.de$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Example: 301

Forwarding to https://

Please use the following rules for redirecting all URLs to https://:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


source URL destination URL

Forwarding to new domain

To redirect an entire domain, use the following rule if the request URI remains identical:

RewriteCond %{HTTP_HOST} !^www\.alte-domain\.de$ [NC]
RewriteRule .*{REQUEST_URI} [L,R=301]


After setting up new mod_rewrite rules, they should be checked for all possible constellations. The external debugging tool is suitable for this. Enter all variants of the URL here to check the various redirects.

Attention: Current browsers use an internal cache for 301 redirects, which is not automatically emptied by emptying the browser cache.