Apache configuration for redirect using httpd.conf and .htaccess

File: /etc/httpd/conf/httpd.conf (older systems used apache.conf)

Default: This disables the processing of .htaccess files for the system.

 <Directory />
 AllowOverride None

or for a specified directory:

 <Directory /home/domain/public_html>
 AllowOverride None

Specify directory containing site or page to be redirected:

 <Directory /root-directory-of-web-site-to-be-redirected>
 AllowOverride All
 AllowOverride parameters: AuthConfig FileInfo Indexes Limits Options

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 / http://www.new-domain.com/

Note: The use of the “/” at the end of the redirected domain. This is necessary so that http://www.old-domain.com/page1.html will be redirected to http://www.new-domain.com/page1.html.


Redirect specified pages:

 Redirect 301 /old-page-1.html http://www.newdomain.com/new-page-1.html
 Redirect 301 /old-page-2.html http://www.newdomain.com/new-page-2.html

You may use the following directives:

 301: permanent
 302: temp
 303: seeother
 410: gone

For example:

 Redirect permanent / http://www.newdomain.com/

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.