HomeDev301 Redirect Code Generator
Web tools

301 Redirect Code Generator

Use this free CalculatorX tool for fast local results with clear formulas, worked examples, and privacy-first browser calculation. Fast and free.

Loading tool…

Loading Preparing tool…

How to use

Follow these steps for a clear answer.

1

Enter the destination URL

Paste the new absolute URL (https://…) and set a delay if you need meta refresh or JS redirects.

2

Generate the snippet

Click Generate to build code for PHP, ASP/ASP.NET, .htaccess, IIS, HTML, or JavaScript.

3

Copy and deploy

Paste into the old page or server config, then verify with an HTTP status check for a true 301.

301 Redirect Code Generator specification

Version 1.0.0 · Last reviewed 2026-07-28

Definition
A 301 redirect permanently moves a URL to a new location and tells browsers and search engines to use the destination going forward.
What it calculates
Copy-paste redirect snippets for PHP, ASP/ASP.NET, Apache .htaccess, IIS, HTML meta refresh, and JavaScript from a target URL and optional delay.
Inputs
  • Target URL (destination)
  • Delay in seconds (client-side / meta refresh)
Outputs
  • Platform-specific redirect code ready to paste
Formula
Server 301: Location header / Redirect rule → destination; Client: meta refresh or JS navigation after delay

Enter a destination URL and optional delay, then generate copy-paste snippets for server or client redirects.

Redirect types

Type Side File type 301 support
PHP Server .php Yes
ASP Server .asp Yes
ASP.NET Server .aspx Yes
Apache .htaccess Server All Yes
IIS web.config Server All Yes
HTML meta refresh Client .html No
JavaScript Client .html No
jQuery Client .html No

Where to place redirect code

Domain changed Server changed Place code on
No No Old page, same server
No Yes Old page, new server
Yes No Old page, same server
Yes Yes Old page, old server

For .htaccess redirects, add rules to the .htaccess file or httpd.conf in the site root.

Generated code examples

PHP 301

<?php
header("Location: http://www.example.com/new-page.php", true, 301);
exit();
?>

.htaccess 301

Redirect 301 /old-page.html http://www.example.com/new-page.html

HTML meta refresh

<meta http-equiv="refresh" content="0; url=http://www.example.com/new-page.html">

After generating

  1. Copy the code to the old page or server config
  2. Test with HTTP status checker
  3. Verify 301 status and correct Location header
Assumptions
  • Server redirects (PHP, .htaccess, IIS) can return a true HTTP 301.
  • HTML meta refresh and JavaScript are client-side and are not SEO-equivalent to HTTP 301.
  • Generation runs locally in the browser; URLs are not uploaded.
Units
  • URL: absolute https:// or http:// string
  • Delay: seconds (non-negative number)
Boundary conditions
  • Empty or invalid URLs produce incomplete snippets—verify before deploying.
  • Delay 0 means immediate client-side navigation when using meta/JS modes.
Example
Target https://example.com/new, delay 0 → PHP header(..., true, 301) or Redirect 301 /old https://example.com/new
Validation cases
  • PHP · https://example.com/new → header Location with status 301
  • .htaccess · /old → https://example.com/new → Redirect 301 /old https://example.com/new
  • Meta refresh · delay 0 → meta http-equiv=refresh content="0; url=..."
Sources
  • RFC 9110 HTTP semantics (3xx redirects)
  • Apache mod_alias Redirect
  • HTML meta refresh (historical)
Last reviewed
2026-07-28
Calculation version
1.0.0

Frequently asked questions

Key distinctions behind the tool.

Which redirect type should I choose?

Use PHP, .htaccess, or IIS for permanent SEO-friendly HTTP 301 redirects. Use HTML or JavaScript only when you cannot change server config.

Can I redirect an entire domain?

Yes. With .htaccess, Redirect 301 / https://newdomain.com/ sends the whole site to the new origin.

How do I verify the redirect works?

Open the HTTP status checker and confirm a 301 response with the expected Location header.

Does the generator support HTTPS redirects?

Yes. Enter https:// URLs for destinations. Prefer server-side 301 for HTTP→HTTPS upgrades.