Web Redirect Checker
FR EN ES

Check your web redirects and HTTP responses



The 301 redirect

A 301 redirect, or permanent redirect, tells the browser and search engine crawlers that the visited page has permanently moved to a new address. Search engines update their index and transfer the SEO "weight" to the new URL.


301 Redirect with PHP

Place at the very beginning of the PHP file, before any HTML output:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.example.net/new-page.php");
exit();
?>


301 Redirect with .htaccess (Apache)

Simple method using the RedirectPermanent directive:

Redirect a single page:

RedirectPermanent /directory/old-page.html https://www.example.net/new-page.html

Redirect an entire directory:

RedirectPermanent /old-directory https://www.example.net/new-directory

Redirect a full domain:

RedirectPermanent / https://www.example.net/


301 Redirect with mod_rewrite (.htaccess)

More powerful, mod_rewrite allows the use of regular expressions. Common examples:

Force HTTPS (HTTP → HTTPS):

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Force www (non-www → www):

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Remove www (www → non-www):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]

Redirect an old URL to a new one:

RewriteEngine On
RewriteRule ^old-page\.html$ /new-page.html [L,R=301]


301 Redirect with Nginx

In the Nginx configuration file (server block):

Redirect a specific page:

location = /old-page.html {
    return 301 https://www.example.net/new-page.html;
}

Force HTTPS:

server {
    listen 80;
    server_name example.net www.example.net;
    return 301 https://$host$request_uri;
}

Force www:

server {
    listen 443 ssl;
    server_name example.net;
    return 301 https://www.example.net$request_uri;
}

Remove www:

server {
    listen 443 ssl;
    server_name www.example.net;
    return 301 https://example.net$request_uri;
}


Note: codes 307 (temporary redirect preserving the HTTP method) and 308 (permanent redirect preserving the HTTP method) also exist but are rarely used in practice.