Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Web Servers ›
Using the Apache Redirect directive

Using the Apache Redirect directive

February 13, 2011 Web Servers Jesin A 1 Comment

Redirecting to another URL and passing the correct HTTP headers is extremely useful from SEO point of view if you migrate your website/blog from one URL to another. Other than redirecting to URL you can also use the redirect directive to send certain HTTP status codes when a page is accessed. The Redirect directive can be used in both the httpd.conf file as well as .htaccess file.
The syntax for Redirect directive is

Redirect [status] url-path url-to-be-redirected

this should be placed inside your .htaccess file or in the httpd.conf file inside the <Directory> directive. The [status] here is optional just using the following code will redirect visitors of your website to the new domain.

Redirect / http://new-domain.com

The status code sent is 302 which means moved temporarily

Redirect 301 moved permanently

By default the redirect directive sends a 302 status code but if you decide to permanently use your new domain you can definitely send a 301 moved permanently statusĀ  code to your website. To do this use the permanent keyword

Redirect permanent / http://new-domain.com

Send a 404 or 410 error code

If for some reason you would like to send a 404 Not Found even for a page that existed you can do so by placing the 404 number in the redirect directive

Redirect 404 /a-directory

Note that after this change if you access this directory http://example.com/a-directory in Firefox you’ll see a blank page instead of your 404 error page but with Internet Explorer you’ll see the IE’s inbuilt 404 message.

The 410 gone code is used to tell that the page is permanently removed and there is no use of accessing it again. To send a 410 for a page

Redirect gone /location

In this way you can send any HTTP status code by following only one rule if the status code is between 300 and 399 the url-to-be-redirected parameter is mandatory else only the url-path needs to be specified. To check whether the correct status code is being returned use the HTTP Headers Lookup Tool

Related posts:

Default ThumbnailRedirect non www to www Default ThumbnailRedirect http to https using htaccess disable directory listing apache thumbnailDisable Directory Listing in Apache Default ThumbnailHow to create custom error page in Apache php category thumbnailRedirecting WordPress archives to a page

Tags: apache, htaccess, redirect

Trackbacks

  1. Redirecting WordPress archives to a page says:
    June 26, 2013 at 4:03 pm

    […] header() is a PHP function using which we are sending a 301 “Permanently Moved” HTTP header with the home page in the “Location:” […]

    Reply

Leave a Reply Cancel reply

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

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.