Skip to content
ToolsFort home

Htaccess Redirect Generator

Htaccess redirect generator: create 301 redirects, force HTTPS, set www or non-www and fix trailing slashes for Apache .htaccess and Nginx.

Updated

Add to your .htaccess file


    

Back up your existing file first and test on a staging site. A wrong rule can take a whole site offline or create a redirect loop.

Use this htaccess redirect generator to write 301 redirect rules without memorising the syntax. Force HTTPS, choose www or non-www, fix trailing slashes and redirect individual pages, and get the rules for both Apache (.htaccess) and Nginx.

How to use the Htaccess Redirect Generator

  1. 1 Choose the site-wide rules you need: HTTPS, www or non-www, and trailing slash handling.
  2. 2 List any page redirects as "/old-page /new-page", one per line.
  3. 3 Copy the Apache or Nginx rules into your server configuration, then test them.

Worked examples

Move one page

Input: /old-page /new-page

Result: Redirect 301 /old-page /new-page

Apache uses a simple Redirect line; Nginx gets an exact-match location block.

Force HTTPS

Input: Redirect all HTTP traffic to HTTPS

Result: RewriteCond %{HTTPS} off + RewriteRule … [L,R=301]

The rule sends every request to the secure version.

Why redirects matter for SEO

When a URL changes or two addresses show the same page, a 301 redirect tells browsers and search engines the move is permanent. Visitors land on the right page, and ranking signals and links pointing at the old address are passed to the new one. Without a redirect you get a 404 error, or two competing versions of the same page.

The redirects most sites need

  • HTTP to HTTPS. Send all traffic to the secure version of the site.
  • www and non-www. Choose one form (for example example.com) and redirect the other, so search engines see a single site.
  • Trailing slashes. /page and /page/ can be treated as two URLs. Pick one and redirect the other.
  • Moved or deleted pages. Point the old URL at the closest matching page, not at the home page.

301 versus 302

A 301 is permanent and is the right choice for moves, merges and site migrations. A 302 is temporary, for example during a short promotion. Using a 302 for a permanent move can slow down the transfer of ranking signals.

Avoid these problems

  • Redirect chains. A to B to C wastes time and can lose signals. Redirect A straight to C.
  • Redirect loops. Two rules that send visitors back and forth break the page. Test every rule.
  • Wrong server. .htaccess only works on Apache (and compatible servers with AllowOverride enabled). Nginx has no .htaccess; its rules go into the server configuration and need a reload.

Always back up your existing file, try the rules on a staging copy first, and check the result with a browser and a header checker.

Frequently asked questions

How do I redirect one page to another in .htaccess?

Add a line such as "Redirect 301 /old-page /new-page" to your .htaccess file. The generator writes it for you and creates the matching Nginx rule.

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

A 301 says the move is permanent, so search engines transfer the old page's signals to the new one. A 302 says it is temporary. Use a 301 for permanent changes.

Does my site have an .htaccess file?

Only if it runs on Apache. Many shared hosts use Apache, while Nginx servers are configured in the server config files instead.

Will redirects hurt my SEO?

No. Correct 301 redirects protect your rankings during a move. Chains, loops and redirecting everything to the home page are what cause problems.

How do I test my redirects?

Open the old URL in a private browser window and confirm you reach the new one. A header checker or the browser developer tools Network tab shows the 301 status.

Esc