Skip to content

.htaccess Redirect Generator

Free

Generate Apache .htaccess redirect rules instantly. Create 301 and 302 redirects, directory redirects, and regex URL rewrites for Apache servers.

.htaccess 301 redirectapache redirect generatorhtaccess rewrite rule generator
All SEO Tools

Settings guide

Simple Redirect directive:

Redirect 301 /old-page.html https://yourdomain.com/new-page

Best for exact URL mappings. Works without mod_rewrite enabled. The source path is relative (no domain); the destination is absolute.

RewriteRule format:

RewriteRule ^old-path/?$ /new-path [R=301,L]

The R=301 flag sets the status code. L means "stop processing rules here." The ? after the slash makes the trailing slash optional.

Common RewriteRule flags:

  • ·[R=301,L] — Permanent redirect, stop processing
  • ·[R=302,L] — Temporary redirect, stop processing
  • ·[NC] — Case-insensitive matching
  • ·[QSA] — Append existing query strings to the new URL

Required directives at the top:

Any file using RewriteRule must begin with RewriteEngine On. If your .htaccess is in a subdirectory, add RewriteBase /subdirectory/.

HTTPS force redirect:

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Format comparison

.htaccess vs Nginx redirects:

.htaccess is Apache-specific and applies per-directory without requiring server restart. Nginx does not support .htaccess — Nginx redirects are configured in the server block configuration files and require a server reload. If your host runs Nginx, use the Nginx format in the redirect builder instead.

.htaccess vs Vercel redirects:

Vercel uses a JSON configuration file (vercel.json) for redirects, not .htaccess. If you are deploying to Vercel, Netlify, or similar serverless platforms, .htaccess rules will be ignored — use the platform-specific format generator instead.

How it works

1

Enter your redirect pairs

Add source paths and destination URLs for each redirect you need to create.

2

Choose directive type

Select simple Redirect directive for exact URLs, or RewriteRule for pattern-based redirects with regex.

3

Set redirect type

Choose 301 (permanent) or 302 (temporary) based on whether the move is permanent.

4

Copy to your .htaccess file

Add the generated rules to your .htaccess file on your Apache server and test each redirect.

About this format

Apache's .htaccess file is the configuration layer that controls redirects, URL rewrites, access rules, and caching headers for Apache web servers. WordPress, many PHP applications, and a large portion of shared hosting environments run on Apache — making .htaccess knowledge essential for anyone managing SEO on these platforms.

Writing .htaccess redirect rules by hand is error-prone. A single syntax mistake — a missing slash, a wrong flag, or an incorrect regex — can cause redirect loops, broken URLs, or accidentally expose server paths. This generator produces verified .htaccess redirect syntax using both the simple `Redirect` directive and the more powerful `mod_rewrite` `RewriteRule` format.

Use the simple `Redirect` directive for exact URL-to-URL redirects. Use `RewriteRule` for pattern-based redirects: forcing trailing slashes, removing index.html from URLs, redirecting all HTTP traffic to HTTPS, redirecting entire subdirectories, or normalizing URL parameters. Both formats are generated with correct flags and tested syntax.

Frequently asked questions

What is an .htaccess file and where is it located?+
An .htaccess file is a directory-level Apache configuration file that controls redirects, URL rewrites, authentication, and caching for that directory and all subdirectories. It is typically located in your web root — the same folder as your index.php or index.html file. The filename starts with a dot, making it a hidden file on Linux systems.
How do I add a 301 redirect in .htaccess?+
Add this line to your .htaccess file: Redirect 301 /old-page https://yourdomain.com/new-page. The source path is the old URL path (no domain, starts with slash). The destination is the full absolute URL including https://. Upload the edited .htaccess file to your server and test the redirect immediately.
Why is my .htaccess redirect not working?+
Common causes are: the .htaccess file is not in the correct directory, mod_rewrite is not enabled on the server, the RewriteEngine On directive is missing, the file has Windows line endings (CRLF) instead of Unix line endings (LF), or a syntax error in the rules. Test with a simple Redirect directive first to rule out mod_rewrite issues.
Can .htaccess redirects cause a redirect loop?+
Yes. A loop occurs when URL A redirects to URL B, which redirects back to URL A. This typically happens when the RewriteRule pattern matches the destination URL too broadly. Add a RewriteCond to exclude the destination from matching, or use more specific regex patterns that only match the exact source URL.
Does .htaccess work on all web hosting plans?+
Apache .htaccess works on Apache web servers, which power most shared hosting plans and many VPS configurations. It does not work on Nginx, LiteSpeed (unless Apache compatibility mode is enabled), or Microsoft IIS servers. Check with your host whether .htaccess is supported and whether mod_rewrite is enabled before deploying redirect rules.

Related tools and guides