Redirect a web site using Apache

The Quick and Dirty Solution
A meta refresh tag added to the "head" **Please replace the "head" to <>** section of a web page will forward a visitor to another page, it looks like this:
meta equiv="Refresh" content="8;URL=http://" --> please add the < > for this line
This tag simply sends a visitor FROM the page they're at, TO somepage.html, after an 8 second delay. W3C says not to use it, it's non-standard, "fast refreshes" are frowned on by SEs due to abuse and, although most spiders follow it, your URLs usually won't be updated in SEs. A five second delay or longer has never caused me SE problems but your mileage may vary. Frankly, meta refresh is a pretty lame solution but when you need something "quick and dirty" until you can implement something better...

Please refer to


  1. Use a CGI script to forward a home page: (mod_cgi)

    File: httpd.conf
    ScriptAlias / /var/www/cgi-bin/redirect-script/
    File: /var/www/cgi-bin/redirect-script
    print "Status: 301 Moved\r\n" .
    "Location:\r\n" .

  2. Use Apache module (mod_rewrite)

    File: httpd.conf
    RewriteEngine On
    RewriteRule /.* [R]
    Forwards all references in entire domain.

  3. Use Apache module (mod_alias )

    File: httpd.conf
    • Redirect Domain:
      Redirect /
      Redirect permanent /
    • Redirect Page:
      Redirect /web-page.html
    • Redirect directives take precedence over Alias and ScriptAlias directives.
    • Other "Redirect" options include: temp (error 302) default - temporary redirect status, seeother (error 303) resource has been replaced and gone (error 410) resource has been permanently removed.
    Example httpd.conf with virtual hosts for multiple domains which all redirect:
    Redirect permanent /

  4. Apache 301 redirect using the .htaccess file:

    If one wants to permanently forward an entire web site to a new URL or forward a single page permanently and have the search engines update their database, one should use a 301 redirect. This may redirect to a new server or to itself but to a different domain. This tutorial shows how. This method is a variation of using the mod_alias redirection shown above except that it allows the customer to redirect themselves by providing a .htaccess file themselves.
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^
    RewriteRule ^(.*)$$1 [R=permanent,L]

Apache configuration for redirect using httpd.conf and .htaccess:

File: .htaccess Create a file /home/domain/public_html/.htaccess in that directory of the domain to be forwarded that looks something like this:
  • Redirect entire domain:

    Redirect 301 /
    Note: The use of the "/" at the end of the redirected domain. This is necessary so that will be redirected to

  • Redirect specified pages:

    Redirect 301 /old-page-1.html
    Redirect 301 /old-page-2.html

You may use the following directives:
  • 301: permanent
  • 302: temp
  • 303: seeother
  • 410: gone
For example:
Redirect permanent /
If an incorrect directive is used in the httpd.conf or .htaccess file it will result in a server error. Check your log files: /var/log/httpd/error_log.

HTTP 1.1 Redirect codes:
HTTP Code Status Description
301 permanent The resource has permanently moved
302 temp The resource has temporarily moved
303 seeother The resource has been replaced and refer to new resource
305 UseProxy Use proxy to access site
307 Temp The resource has temporarily moved
410 Tegone The resource has permanently removed

No comments: