0% found this document useful (0 votes)
51 views17 pages

Common Htaccess 301 Redirect Rules: Create PDF in Your Applications With The Pdfcrowd

This document provides over 20 common htaccess 301 redirect rules for redirecting pages, sites, domains, file extensions and more. It explains what an htaccess file is and how it controls Apache web server directories and subdirectories. Specific rules are given for redirecting single pages, entire sites, subfolders, domains and file extensions while retaining URL structure and query strings.

Uploaded by

Mohammad Tahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views17 pages

Common Htaccess 301 Redirect Rules: Create PDF in Your Applications With The Pdfcrowd

This document provides over 20 common htaccess 301 redirect rules for redirecting pages, sites, domains, file extensions and more. It explains what an htaccess file is and how it controls Apache web server directories and subdirectories. Specific rules are given for redirecting single pages, entire sites, subfolders, domains and file extensions while retaining URL structure and query strings.

Uploaded by

Mohammad Tahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Common

Htaccess 301
Redirect Rules
AUTHOR: Team Linchpin

UPDATED ON: February 13, 2021

PUBLISHED IN: Website Creation

READING TIME:4 min

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In this article, we’ll take a look at:

1) What is an Htaccess file?

2) Common 301 Redirect Htaccess Rules

2.1) How do you redirect a single page?

2.2) How do you redirect an entire site or domain to a new one?

2.3) How do you redirect an entire site to a sub folder?

2.4) How do you redirect a sub folder to different website?

2.5) How do you redirect a file extension but retain the page name?

2.6) How do you use rewriting to redirect from an old domain to a new

domain?

2.7) How do you use rewriting to redirect from a non-www to a www

subdomain?

2.8) How do you use rewriting to redirect a domain to a www location

with a subdirectory?

2.9) How do you use rewriting to redirect from an old domain to a new

domain that includes the full path and query string?

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
2.10) How do you use rewriting to redirect from an old domain with a

subdirectory to new domain without the subdirectory but include the full

path and query string?

2.11) How do you rewrite and redirect URLs with query parameters with

files placed in a root directory?

2.12) How do you redirect URLs with query parameters and place files in

a subdirectory?

2.13) How do you redirect a site to HTTPS from HTTP to eliminate

duplicate content?

2.14) How do you redirect a site from HTTP to HTTPS to eliminate

duplicate content?

2.15) How do you remove an index.html or index.php and redirect to the

root?

2.16) How do you rewrite and redirect URLs with query parameter to

directory based structure while retaining the query string in the URL root

level?

2.17) How do you rewrite URLs with a query parameter to a directory

based structure while retaining query string parameter in the URL

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
subdirectory?

2.18) How do you redirect an old website to a new domain and retain the

URL path?

2.19) How do you rewrite and add a trailing slash to URLs without one?

2.20) How do you redirect from a blog sub domain to to a blog folder?

2.21) How do you redirect one directory to another?

There are common htaccess 301 redirect rules that I find


myself searching for each time I build a website , need to
redirect a page for a SEO strategy for a client, or help with a
website’s SEO transition plan . So I thought I would create a
resource where I could gather all the common rules into one
spot to save me time each project.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
What is an Htaccess
file?
The .htaccess, or Hypertext Access file, is a configuration text
file that controls the directory, as well as any subdirectories,
where it is located on an Apache web server. If you use a
Linux-based web hosting plan, your web properties likely run
on Apache. You may have seen the .htaccess file in certain
directories, particularly if you have deployed WordPress,
Joomla, Drupal or any other content management web
software.

The .htaccess file can include specific instructions to the


server. This file can configure the server to require a
password for the directory where it resides. The .htaccess file
can also be configured to automatically redirect users to
another index file or site, restrict or allow users based on IP

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
addresses, and disable directory listings. You may never
need to edit the .htaccess file, but if you do, you must make
sure that the file is named ‘.htaccess’ only, with the period in
front and no .txt or .htm file extension.

Common 301 Redirect


Htaccess Rules
How do you redirect a single page?
Redirect 301 /pagename.php http://www.domain.com/pagename.html

How do you redirect an entire site or


domain to a new one?
Redirect 301 / http://www.domain.com/

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How do you redirect an entire site to a sub
folder?
Redirect 301 / http://www.domain.com/subfolder/

How do you redirect a sub folder to


different website?
Redirect 301 /subfolder http://www.domain.com/

How do you redirect a file extension but


retain the page name?

Example: If you want an .html extension to use the same


filename but use the .php extension.

RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How do you use rewriting to redirect from
an old domain to a new domain?
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

How do you use rewriting to redirect from a


non-www to a www subdomain?
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

How do you use rewriting to redirect a


domain to a www location with a
subdirectory?
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^( *)$ http://www domain com/directory/index html [R=301 NC]
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RewriteRule (. )$ http://www.domain.com/directory/index.html [R 301,NC]

How do you use rewriting to redirect from


an old domain to a new domain that
includes the full path and query string?
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

How do you use rewriting to redirect from


an old domain with a subdirectory to new
domain without the subdirectory but
include the full path and query string?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How do you rewrite and redirect URLs with
query parameters with files placed in a root
directory?

Example: The original URL being


http://www.website.com/index.php?id=3 and the new URL
being http://www.website.com/path-to-new-location/

RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301]

How do you redirect URLs with query


parameters and place files in a
subdirectory?

Example: The original URL being


http://www.website.com/sub-dir/index.php?id=3 and the

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
new page being http://www.website.com/path-to-new-
location/

RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]

How do you redirect a site to HTTPS from


HTTP to eliminate duplicate content?
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

How do you redirect a site from HTTP to


HTTPS to eliminate duplicate content?
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How do you remove an index.html or
index.php and redirect to the root?
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.php HTTP [NC]
RewriteRule (.*)index.php$ /$1 [R=301,L]

RewriteEngine On
RewriteCond %{THE_REQUEST} /index.html HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]

How do you rewrite and redirect URLs with


query parameter to directory based
structure while retaining the query string in
the URL root level?

Example: The original URL being


http://www.website.com/index.php?id=100 and new page
being http://www.website.com/100/

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]

How do you rewrite URLs with a query


parameter to a directory based structure
while retaining query string parameter in
the URL subdirectory?

Example: The original URL is


http://www.website.com/index.php?category=fish and new
page being http://www.website.com/category/fish/

RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]

How do you redirect an old website to a


new domain and retain the URL path?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]

If you do not want to pass the path to the new domain, change the last line to:
RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L]

How do you rewrite and add a trailing slash


to URLs without one?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301,L]

How do you redirect from a blog sub


domain to to a blog folder?

Example: Redirect blog.oldsite.com to


www.newsite.com/blog/

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How do you redirect one directory to
another?
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $

Need Digital Marketing


Help?
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Feel free to reach out to talk about your digital
marketing project and business goals.

Contact Bill Today

Let's Create Something


Great
   

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
© 2013 - 2021 Linchpin SEO, LLC All Rights Reserved / Sitemap 

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

You might also like