.htaccess Redirect Generator
Generate common Apache .htaccess redirect rules for websites.
Generated .htaccess Rule
Common Uses
- Force HTTPS on all traffic
- Choose either WWW or non-WWW as canonical domain
- Redirect an old page to a new URL
Intro
Generate common Apache .htaccess redirect rules for domain changes, HTTPS enforcement, www redirects, and URL forwarding.
This tool helps you build redirect rules without having to write Apache rewrite syntax from scratch. It is useful when you need to send visitors and search engines from one URL to another, standardize your preferred domain, or force secure HTTPS access.
It is especially useful when you need to:
- redirect HTTP to HTTPS
- redirect non-www to www, or the reverse
- move an old page to a new URL
- forward an entire domain to another domain
- preserve SEO value during site changes
- avoid common rewrite rule mistakes
What Is an .htaccess Redirect?
An .htaccess redirect is a rule placed in an Apache .htaccess file that tells the web server to send requests from one URL to another.
Redirects are commonly used for:
- site migrations
- domain changes
- HTTPS enforcement
- canonical domain handling
- URL cleanup
- preserving old links after page changes
Instead of returning the original page, Apache sends a redirect response telling the browser or crawler where to go next.
This is useful because it helps:
- users reach the correct page
- search engines update indexed URLs
- old links keep working
- traffic flow remain consistent after changes
What This Tool Generates
This generator creates starter Apache redirect rules for common website scenarios.
The current live page includes options for:
- HTTP to HTTPS
- www to non-www
- non-www to www
- old page to new page
- domain to domain
- custom redirect
Common Redirect Types
HTTP to HTTPS Redirect
Use this when you want all visitors to access the secure HTTPS version of the site.
This is commonly used when:
- an SSL certificate is installed
- you want one secure canonical version of the site
- browsers and search engines should always use HTTPS
- you are cleaning up mixed access paths
This is one of the most important redirects for modern websites.
www to non-www Redirect
Use this when you want:
www.example.comto redirect toexample.com
This helps standardize one preferred hostname so users and search engines do not treat both versions as separate URLs.
non-www to www Redirect
Use this when you want:
example.comto redirect towww.example.com
This is equally valid as long as you stay consistent across the site, internal links, and canonical settings.
Old Page to New Page Redirect
Use this when a page has moved permanently.
Examples:
- old blog post URL to new article URL
- outdated service page to updated version
- deleted landing page to replacement content
This helps preserve traffic and avoids broken links.
Domain to Domain Redirect
Use this when a full site or brand moves to a different domain.
This is useful for:
- domain rebranding
- merging websites
- moving from a temporary domain to a permanent one
- consolidating old projects
Custom Redirect
Use a custom rule when your redirect logic needs something more specific, such as:
- pattern-based matching
- conditional rules
- path preservation
- advanced rewrite behavior
Why Redirects Matter
Redirects are not just for convenience. They also affect:
- user experience
- SEO continuity
- link preservation
- crawl efficiency
- canonical site structure
- migration success
A good redirect strategy helps prevent:
- broken links
- duplicate hostname issues
- insecure HTTP access
- traffic loss after URL changes
- confusion between old and new site structures
For many websites, redirects are one of the most important parts of a migration or cleanup project.
301 vs 302 Redirects
Understanding the difference between redirect types is important.
301 Redirect
A 301 is a permanent redirect.
Use it when:
- the move is permanent
- the old URL should no longer be used
- you want search engines to treat the new URL as the main destination
This is the most common choice for page moves, HTTPS enforcement, and domain canonicalization.
302 Redirect
A 302 is usually treated as a temporary redirect.
Use it when:
- the move is temporary
- you expect the original URL to return later
- you are testing or temporarily rerouting traffic
For most long-term site changes, 301 is the better choice.
Common Redirect Use Cases
Forcing HTTPS
A redirect sends all insecure HTTP requests to the secure HTTPS version of the site.
This is useful for:
- site security
- browser trust
- canonical consistency
- reducing duplicate access paths
Choosing a Preferred Domain
A redirect helps enforce one version of the hostname.
Examples:
- always use
example.com - always use
www.example.com
Without this, users and crawlers may access the same site through multiple versions.
Redirecting Deleted or Renamed Pages
If a page is removed or renamed, a redirect can send users to the best replacement instead of leaving them on a broken URL.
Domain Migrations
A domain-to-domain redirect is important when moving a site from one brand or hostname to another.
This helps preserve:
- bookmarks
- external links
- user trust
- search visibility
Campaign or Vanity URLs
Redirects can also be used to send short or memorable URLs to deeper destination pages.
Common .htaccess Redirect Mistakes
Redirect Loops
A bad rule can cause the browser to redirect repeatedly without reaching a final destination.
This often happens when:
- HTTP and HTTPS rules conflict
- www and non-www rules fight each other
- proxy or CDN logic overlaps Apache rules
Using the Wrong Redirect Type
Using a temporary redirect for a permanent move can create confusion for users and search engines.
Stacking Too Many Rules
Large .htaccess files with many overlapping rules can become hard to maintain and debug.
Forgetting HTTPS Preconditions
Do not force HTTPS unless the certificate is installed and the HTTPS site actually works.
Breaking Existing Paths
A domain or page redirect may accidentally drop or change paths if the rule is not written carefully.
Testing Only One Hostname
A redirect may work on one version of the site but fail on another.
Always test:
- HTTP
- HTTPS
- www
- non-www
How to Use Redirect Rules Safely
A safe workflow for redirect changes is:
- choose the exact redirect goal
- generate the starting rule
- back up the current
.htaccessfile - add the new rule carefully
- test all hostname variations
- confirm there are no redirect loops
- verify old URLs reach the correct final destination
This is especially important on live production sites, where one bad rewrite can affect the whole domain.
Best Practices for Apache Redirects
When working with .htaccess redirects, it helps to:
- keep one clear canonical hostname
- prefer
301for permanent site changes - test redirects with and without
www - test both HTTP and HTTPS
- avoid duplicate or conflicting rules
- document why a redirect exists
- remove outdated rules during cleanup
- recheck redirects after hosting or CDN changes
For larger sites, it is also smart to keep redirect logic documented outside the .htaccess file so future changes are easier to manage.
Example Redirect Scenarios
Redirect HTTP to HTTPS
Use this when the goal is:
- secure all traffic
- standardize the site on HTTPS
- reduce duplicate access paths
Redirect www to non-www
Use this when your preferred canonical domain is the root domain without www.
Redirect non-www to www
Use this when your preferred canonical domain includes www.
Redirect an Old Page to a New Page
Use this when:
- a page slug changes
- content is reorganized
- an old resource has a new permanent location
Redirect One Domain to Another
Use this when:
- a project changes brand
- a business moves to a new domain
- multiple sites are being consolidated
Frequently Asked Questions
What does an .htaccess redirect do?
It tells Apache to send requests from one URL or hostname to another URL or hostname.
Should I use a 301 or 302 redirect?
Use 301 for permanent changes and 302 for temporary ones.
Can I force HTTPS with .htaccess?
Yes, as long as HTTPS is already configured and working properly on the site.
What is the difference between www and non-www redirects?
They control which hostname version becomes the preferred canonical version of the site.
Why is my redirect looping?
This usually happens because multiple rules conflict or because HTTP/HTTPS and www/non-www logic overlap incorrectly.
Do redirects help preserve old links?
Yes. Proper redirects help visitors and search engines reach the new destination instead of hitting a dead page.
Related Tools
You may also find these tools useful:
- Nginx Config Generator
- HTTP Header Checker
- SSL Certificate Checker
- DNS Lookup Tool
- Website Speed Test
Final Note
This .htaccess Redirect Generator is useful for building common Apache redirect rules quickly without having to remember rewrite syntax from memory.
Use it to create a starting rule, then test carefully across all domain variations so you do not introduce loops, broken paths, or conflicting redirect behavior.
