Apache Web Server Configuration For Web Site Redirect
Apache Web Server Configuration For Web Site Redirect
html
Web site redirects for entire domain or individual pages. This Apache forwarding
multiple solutions and their nuances.
search | Home Page | Linux Tutorials | Terms | Privacy Policy | Advertising | Contact
|
6
List of methods used to redirect a web site
Related YoLinux
Tutorials: using Apache:
°Web Site Password 1. One can forward a web page URL or home page
Protection using the following web page with the "Refresh"
directive:
°Internet Security
or:
01 <html>
02 <head>
03 <META HTTP-EQUIV="Refresh"
Content="3;
URL=http://www.company.com/dir1/">
04 </head>
05 <body>
06 This page will forward to
http://www.company.com/dir1/ in three
seconds.
07 <p>
08 Please update your links.
09 </body>
10 </html>
1 ScriptAlias / /var/www/cgi-bin
/redirect-script/
File: /var/www/cgi-bin/redirect-script
1 #!/usr/bin/perl
2
3 print "Status: 301 Moved\r\n" .
4 "Location: http://www.new-
domain.com/\r\n" .
5 "\r\n";
or:
1 #!/usr/bin/perl -w
2 use strict;
3 use CGI qw/:standard/;
4 print redirect('http://www.new-
domain.com');
1 <?php
2 header("Location: http://www.new-
domain.com/");
3 ?>
01 <html>
02 <head>
03 <script language="Javascript"
type="text/javascript"> Advertisement
04 <!-- Hide script
Ads by Google 05 //<![CDATA[ Levono UK:
► Apache 06 window.location.href="http://www.new-
domain.com/"
► Linux Tutorial 07 //]]> End script hiding -->
08 </script>
► Apache Log Files 09 </head>
10 </html>
Free Information
Technology 5. Use Apache module (mod_rewrite)
Magazines and File: httpd.conf
Document Downloads
1 RewriteEngine On
2 RewriteRule /.* http://www.new-
domain.com/ [R]
1 Redirect / http://www.new-
domain.com/
or
1 Redirect permanent /
http://www.new-domain.com/
Redirect Page:
1 Redirect /web-page.html
http://www.new-domain.com
/destination-web-page.html
Note:
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.
1 <VirtualHost XXX.XXX.XXX.XXX>
2 ServerName directtolinux.com
3 ServerAlias
www.directtolinux.com
4 ServerAlias direct-to-linux.com
5 ServerAlias www.direct-
to-linux.com
6 ServerAlias digitalpenguins.com
7 ServerAlias
www.digitalpenguins.com
8 Redirect permanent /
http://www.yolinux.com/
9 </VirtualHost>
Jobs
7. Apache 301 redirect using the .htaccess file:
J2EE Applications
Developer with...
If one wants to permanently forward an entire Warrenville, IL
web site to a new URL or forward a single TeamBradley
page permanently and have the search Technology Programmer
engines update their database, one should - Next Gen...
use a 301 redirect. This may redirect to a new United Kingdom
server or to itself but to a different domain. Interactive Selection
This tutorial shows how. This method is a Specialist Embedded
variation of using the mod_alias redirection Software Developer
shown above except that it allows the Austin, TX
3M
customer to redirect themselves by providing a
.htaccess file themselves. Principal Software
Engineer - Lead
San Mateo, CA
Akamai Technologies
1 RewriteEngine on
2 RewriteCond %{HTTP_HOST} Senior C++ Developer
^yolinux.com Bridgend, Mid
3 RewriteRule ^(.*)$ Glamorgan, United
http://www.yolinux.com/$1 Kingdom
[R=permanent,L] Hays - West and Wales
Software Developer -
This example forwards http://yolinux.com to Cloud Environment
http://www.yolinux.com/ to unify your site to Kildare, Kildare, Ireland
Experis IT
a single URL. This can also simplify your web
logs if they can not distinguish between the J2EE Developer for an...
1 <Directory /home/domain/public_html>
2 AllowOverride None
3 </Directory>
1 <Directory /root-directory-of-web-
site-to-be-redirected>
2 AllowOverride All
3 </Directory>
1.html
2 Redirect 301 /old-page-2.html
http://www.newdomain.com/new-page-
2.html
301: permanent
302: temp
303: seeother
410: gone
For example:
1 Redirect permanent /
http://www.newdomain.com/
HTTP
Status Description
Code
The resource has permanently
301 permanent
moved
The resource has temporarily
302 temp
moved
The resource has been
303 seeother replaced and refer to new
resource
305 UseProxy Use proxy to access site
The resource has temporarily
307 Temp
moved
The resource has permanently
410 Tegone
removed
Links:
"Apache Server
Bible 2"
by Mohammed J.
Kabir
ISBN #
0764548212,
Hungry Minds