Friday, July 8, 2011

How to redirect an URL in Apache web server


URL redirection, also called URL forwarding and domain redirection also called domain forwarding

To redirect oldserver.com to newserver.com, add the following line in the httpd.conf file

RedirectPermanent / "http://www.newserver.com/"

Sample httpd.cong

< VirtualHost 192.168.1.1:* >
DocumentRoot /var/www/html/web/
ServerName oldserver.com
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
< Directory "/var/www/html/web" >
allow from all
Options -Indexes
DirectoryIndex index.html
RedirectPermanent / "http://www.newserver.com/"
< /Directory >
< /VirtualHost >