Auto redirect of all pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpJames
Forum Newbie
Posts: 2
Joined: Tue Aug 09, 2005 10:44 am

Auto redirect of all pages

Post by phpJames »

I am quite new to PHP, and have heard that there is a way of redirecting all files on my site to another.

For example, no matter whether the visitor tries to access http://www.mysite.com/shop.php or http://www.mysite.com/contact.php, or any other page, they'll always be redirected to http://www.myothersite.com/index.php

I simply want to catch all visitors to my old site, and immediately transfer them to my new one. I've heard it can be done by editing one file, rather than every file on the site. Can anyone please offer specifics?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

I think you might be talking about the .htaccess file.

For tutorials on htaccess, Google is your friend...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

if there's a single file you include in all of the pages of the old site

like include 'databaseinfo.php';
or
include 'header.php';

You could put a simple header location at the top of one of those files.

Code: Select all

header("Location: http://www.domain.com");
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Easy method
set the 404 page to index.php

more 'involved' method
write a rewrite rule for every old file, rewriting it to the index file
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

redirect directive in .htaccess file.
phpJames
Forum Newbie
Posts: 2
Joined: Tue Aug 09, 2005 10:44 am

Post by phpJames »

Excellent, thanks a lot guys. That htaccess directive is exactly what I was looking for. :D
Post Reply