Excellent Tricks For Redirection A Codes Collection

Find below code snippets for Redirection, Change your domain name accordingly

HTML Redirect / Javascript

Table of Contents

Simple Html + Javascript Redirect

<html lang="en-US">
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="0; url=">
        <script type="text/javascript">
            window.location.href = ""
        <title>Redirect Me to</title>
        <!-- Mention to Redirect, If Not Automatically -->
        If you are not redirected automatically, follow this <a href=''>link to NETNAPS</a>.

FallBack – Redirect if Javascript is not Allowed


    <a href="">Click here if you are not redirected automatically.</a>

Redirection With Meta Tag in Delayed Seconds

This is 5 seconds Delayed delay as you like

<meta http-equiv="refresh" content="5; url=" />

INIT Function With HTML Redirection

<!DOCTYPE html>
            function init()
               window.location.href = "";

    <body onload="init()">

Apache Server .htaccess Redirections

Permanent Redirect 301 Non-www to www

#redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Redirecting permanently www to non-www domain

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

Redirecting a www domain with folder or sub-directory permanent 301

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} [NC]
RewriteRule ^(.*)$ [R=301,NC

Redirect an old domain to the new one with a full query string and path

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*){REQUEST_URI} [R=302,NC

Redirect The Entire Web Site

Redirect 301 /

Redirecting a particular page

Redirect 301 /index.php

Redirect the Site to a Folder / Directory

Redirect 301 /

HTML to PHP File Redirection

RedirectMatch 301 (.*)\.html$$1.php

Redirecting an Old Domain to A New Domain

RewriteEngine on
RewriteBase /
RewriteRule (.*)$1 [R=301,L]

Nginx Redirects

Nginx All HTTP Requests to HTTPS

Use anyone both worked for me, If you use 443 Port use First One

server {
  listen [::]:80;
  listen      80;

  # Redirect all non-https requests
  rewrite ^ https://$host$request_uri? permanent;

server {
  listen              80;
  listen              [::]:80;
  location '/var/www/netnaps' {
  default_type "text/plain";
  root        /tmp/dir;

  location / {
    return              301 https://$server_name$request_uri;

PHP Redirects

    Header("HTTP/1.1 301 Moved Permanently");

By Rahul Kharbanda

I am Rahul Kharbanda from India. I hope you like all the content I made. Welcome to comment & connect.
I am on Quora , Github , Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *