Skip to content
andcode Tools

.htaccess Redirect Generator

🔒 Runs in your browser

Redirect rules

Site-wide options

Generated .htaccess

What .htaccess redirects do

.htaccess is a per-directory configuration file read by the Apache web server (the software behind most cPanel and shared-hosting accounts). Drop one in your site root and you can send visitors and search engines from an old URL to a new one without touching your application code. This builder writes those rules for you using mod_rewrite — RewriteEngine On followed by RewriteCond/RewriteRule lines — so the ordering is deterministic and every source path is anchored and escaped to match only the URL you intend.

301 vs 302, and canonicalisation

A 301 is a permanent redirect: browsers cache it and search engines pass the old page's ranking to the new one — use it when a page has moved for good. A 302 is temporary and tells engines to keep the original URL indexed — use it for short-lived campaigns or A/B tests. Beyond individual pages, the toggles let you force every request onto https:// and pick a single canonical host (www or the naked domain), which prevents duplicate-content splits and keeps one authoritative address for your site.

Where the file goes and how to test it

Copy the generated snippet into a file named exactly .htaccess (note the leading dot, no extension) in your site's document root — usually public_html. If a file already exists, add these rules near the top. Because rules are evaluated top to bottom and each one ends in [L], order matters: put canonicalisation first, then your most specific path redirects. After uploading, visit an old URL and confirm your browser lands on the new address with the expected status code.

Frequently asked questions

Where do I put the .htaccess file?

Save the snippet as a file named exactly .htaccess (leading dot, no extension) in your site document root, usually public_html. If one already exists, paste these rules near the top.

What is the difference between a 301 and a 302 redirect?

A 301 is permanent: it is cached and passes SEO ranking to the new URL. A 302 is temporary and keeps the original URL indexed. Use 301 for moved pages, 302 for short-lived campaigns.

Does the order of the rules matter?

Yes. Apache reads rules top to bottom and each one ends in [L], which stops processing at the first match. Put canonicalisation (HTTPS, www) first, then your most specific path redirects.

Does this work on Nginx or IIS?

.htaccess is an Apache feature, used by most cPanel and shared hosting. Nginx and IIS ignore it and use their own config formats, so these rules will not apply there.

Related tools

Clear local data?

This permanently erases everything this site has saved in this browser:

  • Saved audio projects (Audio Mixer autosave)
  • Project boards, cards and attachments (Kanban)
  • Your favorite tools
  • Preferences, such as your language choice

This can't be undone, and it only affects this browser on this device.