Htaccess Redirect Generator
Generate Apache .htaccess rules for page redirects, HTTPS, www, trailing slashes and domain moves, with loop and chain checks before you deploy.
Page redirects
old => new. Use 410 as the target to mark a page gone. Lines starting with # are ignored.^blog/(.*)$ => /news/$1.
Site-wide rules
Domain migration
Keep going with other free EnjoySEOs tools. No signup, no limits.
No tools match your search. Try a different keyword.
An .htaccess Redirect Generator helps you create redirect rules for Apache web servers without writing every directive manually. Generate code for permanent redirects, temporary redirects, old URLs, changed page paths, directory migrations, and other common URL changes. Review the output and add the appropriate rule to your website's .htaccess file to direct visitors and search engines to the intended destination.
What Is an .htaccess Redirect Generator?
An .htaccess Redirect Generator is a tool that produces redirect directives for Apache-compatible web servers. These rules can tell a browser or search crawler to request a different URL when it visits an old address. This is useful when pages move, website structures change, domains are migrated, or duplicate URL versions need to be consolidated.
The generated code may use Apache's Redirect directive from mod_alias or rewriting rules from mod_rewrite. Simple URL changes can often be handled with a Redirect directive, while RewriteRule and RewriteCond offer additional flexibility for pattern matching and conditional redirects.
Unlike a redirect plugin that manages changes through a content management system, an .htaccess rule is interpreted by the web server. This makes it useful for managing redirects at the server configuration level, provided that the hosting environment supports the required directives.
Important: The .htaccess file is primarily used with Apache HTTP Server and compatible environments. Nginx uses a different configuration format, so Apache directives should not be copied directly into an Nginx configuration.
What Does an .htaccess Redirect Generator Do?
A redirect generator converts the source URL, destination URL, and selected redirect behavior into server configuration code. Depending on the tool, it may generate rules for these situations:
- 301 permanent redirects: Redirect visitors from an old URL to a replacement that has become permanent.
- 302 temporary redirects: Send visitors to a different URL temporarily while the original address remains intended for use.
- Single-page redirects: Redirect a retired page to its relevant replacement.
- Directory redirects: Move a group of URLs from an old path to a new directory while preserving the remaining path.
- Domain redirects: Send visitors from an old domain to a new domain.
- HTTPS redirects: Redirect HTTP requests to the HTTPS version of a site.
- Pattern-based redirects: Use matching rules to handle multiple URL paths with a common structure.
- URL consolidation: Help standardize URL versions when used alongside appropriate redirects and canonicalization signals.
Available options vary between generators. Always inspect the code to confirm that it uses the intended redirect status, matches the correct source URL, and sends visitors to the right destination.
What Is an .htaccess File?
An .htaccess file is a per-directory configuration file used by Apache HTTP Server. It can control supported settings for the directory where it is placed and its applicable subdirectories. Depending on server configuration, it can contain redirect rules and rewrite directives without requiring direct changes to the main server configuration.
On many shared hosting environments, website owners can find or edit the file through a hosting control panel, file manager, or SFTP client. It is often located in the website's document root, alongside directories and files used by the site.
Whether a directive works depends on server configuration, module availability, and the permissions allowed through Apache's AllowOverride or AllowOverrideList settings. If these settings prohibit a directive, adding it to .htaccess will not make it work.
For more information about file behavior and configuration requirements, consult the official Apache .htaccess documentation.
301 vs. 302 Redirects
Choosing the correct redirect status is important because it communicates whether a URL move is permanent or temporary. The appropriate status depends on the reason for the redirect and whether the original URL is expected to return.
| Feature | 301 Redirect | 302 Redirect |
|---|---|---|
| Meaning | The resource has moved permanently. | The resource is temporarily available at another URL. |
| Typical use | Permanent URL changes, page migrations, and replaced content. | Temporary maintenance, short-term routing changes, and temporary campaigns. |
| Original URL | Not expected to serve the original resource at that address. | May be used again when the temporary redirect ends. |
| SEO consideration | Signals a permanent move to search engines. | Signals a temporary move rather than a permanent replacement. |
| Apache example | Redirect 301 /old/ /new/ |
Redirect 302 /temporary/ /destination/ |
Use a 301 redirect when the URL change is permanent. Use a 302 when the change is temporary. Do not choose a permanent redirect simply because it is commonly used for SEO; match the status to the actual behavior you intend.
How to Use an .htaccess Redirect Generator
Follow these steps to create and implement a redirect rule for an Apache-compatible website.
1. Identify the old URL
Determine the exact URL that should trigger the redirect. Check the protocol, domain, path, capitalization where relevant, and trailing slash. If you are redirecting an entire directory or a group of URLs, identify the common path pattern you want the rule to match.
2. Enter the destination URL
Provide the URL visitors should reach after requesting the old address. The destination should be relevant to the original page and should resolve successfully. Avoid redirecting unrelated pages to a generic destination simply to eliminate old URLs.
3. Select the redirect type
Choose a permanent redirect for a completed URL move or a temporary redirect when the original URL may be used again. If the generator offers a rule type such as a simple redirect or a RewriteRule, choose one appropriate to the change you need.
4. Generate and review the code
Generate the rule and inspect the source pattern, destination, status code, and any flags. Make sure the rule does not inadvertently match more URLs than intended. Pattern-based rules deserve particular care because a small expression change can affect many pages.
5. Back up your existing .htaccess file
Download or copy the current file before making changes. The file may contain redirects, security directives, caching rules, and CMS-generated configuration. Keep the backup so that you can restore the previous state if the new rule causes an error.
6. Insert the rule in the correct location
Add the generated directive to the applicable .htaccess file. For rewrite-based redirects, the order of rules matters. On WordPress sites, custom redirects are commonly placed before the standard WordPress rewrite block when that placement is appropriate, but existing rules and hosting configuration should be checked first.
7. Test the old and new URLs
Open the original URL and confirm that it redirects to the intended destination with the expected status code. Test similar paths, query strings, trailing-slash versions, and other important variations to make sure that the rule has not created an unwanted redirect or loop.
Common .htaccess Redirect Examples
The following examples illustrate common Apache redirect patterns. Replace the example paths and domains with your actual URLs, and check that your server supports the directives before using them.
1. Redirect one old page to a new page
Use a simple Redirect directive for a straightforward URL move. The following example permanently redirects an old page to a replacement URL.
Redirect 301 /old-page/ https://www.example.com/new-page/
This uses Apache's mod_alias. The path-based Redirect directive matches requests beginning with the specified source path, so consider its prefix behavior when the old path could also match other URLs.
2. Redirect a page using RewriteRule
For a more specific path match, you can use mod_rewrite. In a per-directory .htaccess file, the RewriteRule pattern is normally matched without the leading slash.
RewriteEngine On
RewriteRule ^old-page/?$ https://www.example.com/new-page/ [R=301,L]
The pattern matches old-page with or without its trailing slash. The R=301 flag issues a permanent redirect, and L stops processing the current rewrite ruleset for that request.
3. Redirect an old directory to a new directory
When a directory has moved, a pattern-based rule can preserve the rest of the URL path. For example, it can redirect a page within an old section to the corresponding path inside a new section.
RewriteEngine On
RewriteRule ^old-section/(.*)$ https://www.example.com/new-section/$1 [R=301,L]
The captured portion of the old path is inserted into the destination. A request for /old-section/article/ can therefore redirect to /new-section/article/. Test nested paths carefully before applying a rule to a large directory.
4. Redirect an old domain to a new domain
During a domain migration, you may need to send requests made to an old hostname to the replacement domain while keeping the requested path.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-example\.com$ [NC]
RewriteRule ^ https://www.new-example.com%{REQUEST_URI} [R=301,L]
This example matches the specified old hostname, with or without its www prefix, and directs requests to the new domain. Review all old and new hostname variants, HTTPS settings, and DNS configuration before using a domain-wide rule.
5. Redirect HTTP to HTTPS
If HTTPS is correctly configured and your website should always use secure connections, an Apache rewrite rule can redirect HTTP requests to HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This example relies on Apache's %{HTTPS} variable. Websites behind a reverse proxy, load balancer, or CDN may require a hosting-specific approach because Apache might not see the original connection protocol in the same way as the visitor. Test this rule to avoid redirect loops.
6. Create a temporary redirect
Use a temporary status when a page is only being redirected for a limited period and the original address is expected to be used again.
Redirect 302 /temporary-page/ https://www.example.com/temporary-destination/
Once the temporary situation ends, remove the redirect or restore the intended URL behavior. If the URL has actually moved permanently, update the rule to match the permanent change.
Redirect Directive vs. RewriteRule
Apache supports more than one way to implement redirects. The simplest method is often preferable for a straightforward URL mapping, while rewrite rules are useful when the redirect depends on a pattern or condition.
| Feature | Redirect / RedirectMatch | RewriteRule / RewriteCond |
|---|---|---|
| Apache module | mod_alias |
mod_rewrite |
| Typical use | Simple redirects from one path or matching path pattern to another. | Conditional redirects, URL pattern matching, and more advanced rewriting. |
| Syntax | Generally simpler for basic redirects. | Uses regular-expression patterns and optional conditions and flags. |
| Complexity | Suitable for common URL mappings. | Useful when rules need to inspect hostnames, protocols, or other request conditions. |
| Potential concern | Path matching and rule ordering still need to be considered. | Incorrect patterns or conditions can cause redirect loops or unintended matches. |
For a simple old-to-new path mapping, Apache's Redirect directive may be sufficient. Use RewriteRule and RewriteCond when you need the extra control they provide. Avoid adding multiple conflicting rules for the same URL unless the interaction is understood and tested.
See the Apache mod_alias documentation and the Apache rewrite flags reference for details about supported directives and flags.
Common .htaccess Redirect Errors and How to Fix Them
Redirect loops
A redirect loop occurs when one URL repeatedly sends visitors to another URL that eventually redirects back to the first. This can happen when HTTP-to-HTTPS rules conflict with proxy settings or when old and new URL conditions overlap. Review the complete redirect chain and make sure that the destination no longer matches the redirect condition unintentionally.
Incorrect source or destination paths
A missing slash, wrong hostname, or incorrect path pattern can send users to an unintended destination. Compare the actual requested URL with the rule's matching behavior, particularly when working with nested directories and regular expressions.
Internal server error after editing .htaccess
A syntax error or a directive that the server does not permit in .htaccess can cause an HTTP 500 response. Restore the backup if the site becomes unavailable, then inspect the server error log and correct the specific rule or configuration problem before trying again.
Rules do not take effect
The server may not have the required rewrite module enabled, or its configuration may prevent the directive from being used in .htaccess. Check the hosting environment, directive permissions, and file location. On servers that do not use Apache-compatible per-directory configuration, you will need the appropriate configuration method instead.
Redirects match more pages than expected
Some redirect directives match a path prefix, while RewriteRule patterns can match a broad set of paths if they contain wildcards. Use a more specific pattern when necessary and test both the intended URL and nearby paths that should not be redirected.
WordPress rules conflict with custom redirects
WordPress can generate its own rewrite rules in the .htaccess file. Custom redirects placed in the wrong location or patterns that overlap with WordPress rules may lead to unexpected routing. Back up the file, examine the generated block, and test the placement of each custom rule before deploying it.
Old redirects remain cached
Browsers may cache permanent redirects, and caching layers or CDNs may retain redirect responses. After making changes, test with a command-line client or a clean browser session and inspect the actual HTTP response. Clearing applicable caches may help, but a cached browser redirect can continue to affect testing.
Multiple redirects create unnecessary hops
If an old URL redirects to an intermediate URL that redirects again to the final destination, visitors and crawlers must follow additional steps. Where practical, update the original rule to point directly to the final destination and test the full redirect chain.
.htaccess Redirect Best Practices
Follow these practices to make redirects easier to maintain and reduce the chance of unintended website problems.
- Back up before editing: Keep a copy of your existing .htaccess file before adding or changing rules.
- Choose the correct status code: Use a permanent redirect for a permanent move and a temporary redirect for a temporary situation.
- Redirect to relevant content: Send the old URL to its direct replacement whenever possible.
- Use specific patterns: Avoid broad rules that redirect unrelated pages unintentionally.
- Check rule order: Earlier matching rules and interactions with CMS-generated directives can affect the outcome.
- Prevent redirect loops: Confirm that the destination does not repeatedly match another redirect condition.
- Test query strings: Check whether existing query parameters should be preserved, changed, or discarded.
- Keep URL signals consistent: Align redirects with canonical links, internal links, and sitemap entries when appropriate.
- Test before production changes: Use a staging environment when possible, especially for domain-wide or HTTPS rules.
- Document important changes: Record the purpose of complex redirect rules so future site maintenance is easier.
Recommended workflow: Generate the rule, review its matching conditions, back up .htaccess, implement the change, and test the old URL, destination URL, status code, and any related URL variations.
Does an .htaccess Redirect Help SEO?
Redirects can support technical SEO when URLs move or duplicate addresses need to be consolidated. A correctly implemented permanent redirect helps communicate that the original URL has been replaced and guides visitors and crawlers to the new location.
Redirects do not automatically improve rankings. Their value depends on the reason for the change, the relevance of the destination, and the way the redirect is implemented. Redirecting unrelated pages to a homepage or an irrelevant destination is generally not a good substitute for preserving useful content.
During site migrations, keep redirects to relevant new URLs, update internal links and sitemaps, verify canonical declarations, and monitor important pages after launch. A clean redirect plan helps users reach the correct content and provides search engines with clearer URL signals.
Frequently Asked Questions
What is an .htaccess Redirect Generator?
An .htaccess Redirect Generator creates Apache-compatible redirect rules from your chosen source URL, destination URL, and redirect type. It helps you generate code for common URL changes without manually writing each directive.
What is an .htaccess redirect?
An .htaccess redirect is a server-level instruction that sends a request for one URL to another address. On supported Apache servers, redirects can be configured with directives such as Redirect or rewrite rules such as RewriteRule.
Where is the .htaccess file located?
It is commonly located in a website's document root, although additional .htaccess files may exist in subdirectories. Depending on your hosting setup, you can access it through a control panel, file manager, or SFTP client. Hidden files may need to be displayed in the file manager.
Should I use a 301 or 302 redirect?
Use a 301 redirect when a URL has moved permanently. Use a 302 redirect when the move is temporary and the original URL is expected to be used again. Choose the status that accurately reflects your intended behavior.
Can I use .htaccess redirects on WordPress?
Yes, when the WordPress website runs on Apache or a compatible environment that supports .htaccess directives. Back up the file and check how custom rules interact with WordPress-generated rewrite rules before making changes.
Will .htaccess redirects work on Nginx?
No. Nginx does not read Apache .htaccess files. Redirects on an Nginx server must be configured using the appropriate Nginx configuration directives or a supported hosting interface.
Why does my .htaccess redirect cause an HTTP 500 error?
A server error can occur because of invalid syntax, unsupported directives, incorrect rewrite flags, or configuration restrictions. Restore your backup if needed and check the server error log for the specific issue before reapplying the rule.
Can I redirect an entire directory to another directory?
Yes. A suitable Redirect or RewriteRule can send requests from an old directory to a new path. If you need to preserve the remaining path, use a rule designed to capture and reuse that portion of the URL, then test nested URLs carefully.
Do .htaccess redirects preserve query parameters?
Query-string handling depends on the directive and the generated target. RewriteRule generally preserves the original query string when the substitution does not specify a new query string, unless flags or other rules change that behavior. Test parameterized URLs before deploying a redirect that affects them.
Can too many redirects affect website performance?
Long redirect chains add extra HTTP requests before a visitor reaches the final page. Where practical, redirect old URLs directly to their final destinations and remove outdated intermediate hops when it is safe to do so.
How do I test an .htaccess redirect?
Request the old URL and inspect the returned HTTP status code and Location header. Confirm that the browser reaches the intended destination and that similar URLs are handled correctly. Test for redirect loops, unwanted query-string changes, and unexpected server errors before deploying the rule broadly.
