Page 1 of 1
Is there a way to redirect pages?
Posted: Wed Mar 08, 2006 11:41 am
by ljCharlie
I was wondering if there is a way to redirect pages. For example, I have the following pages:
page1.php
page2.php
page3.php
When people typed in or link from other pages to the following:
http://www.mydomain.com/page1.php, I want to redirect to mypage.php?id=1
http://www.mydomain.com/page2.php, I want to redirect to mypage.php?id=2
http://www.mydomain.com/page3.php, I want to redirect to mypage.php?id=3
Is this possible?
Posted: Wed Mar 08, 2006 11:43 am
by shiznatix
well you can do a few things. you could do a mod rewrite (i think but i have never done one so i don't know for sure) and you can do this (the easy way)!
Code: Select all
switch ($_GET['id'])
{
case 1:
header("Location: http://www.website.com/page1.php");
break;
case 2:
header("Location: http://www.website.com/page2.php");
break;
case 3:
header("Location: http://www.website.com/page3.php");
break;
case 4:
header("Location: http://www.website.com/page4.php");
break;
}
EDIT: sorry I read that backwards as you can tell. Mod Rewrite is what you are looking for.
Posted: Wed Mar 08, 2006 12:34 pm
by ljCharlie
Thank you for the response. Any source on how to rewrite the Mod?
Posted: Wed Mar 08, 2006 12:36 pm
by feyd
Posted: Wed Mar 08, 2006 1:06 pm
by ljCharlie
By the way, is mod rewrite requries access the apache web server? If it is then this is not an option because I don't have access to the apache web server.
Posted: Wed Mar 08, 2006 1:08 pm
by R4000
not true, mod_rewrite may be enabled (it is quite popular, so likely to be enabled). and you can use a .htaccess file to do it!
Posted: Wed Mar 08, 2006 1:35 pm
by ljCharlie
Okay. I'm looking at my web folder and I do see the .htaccess file. I open this up and saw this:
ErrorDocument 404 /errors/404.php?emailaddress=
myemail@mydomain.com
Is this mean I can use .htaccess to redirect missing pages to other current pages? If so, how do I do it? Resource?
Posted: Wed Mar 08, 2006 2:29 pm
by ljCharlie
Okay, here's what I tried.
RewriteEngin On
RewriteBase /
RewriteRule ^scholarships\.php$ foundAll.php?id=1
The error is:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator,
myAdmin@mydomain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.0.54 (Win32) PHP/5.0.4 Server at
http://www.mydomain.com Port 80
Posted: Wed Mar 08, 2006 2:36 pm
by R4000
Can't remember off by heart.
But i'm 99% sure this should work for you:
Code: Select all
RewriteEngine on
RewriteRule ^page([0-9]).php$ mypage.php?page=$1
That should make any of the following pages goto the corrosponding url (NOT A VISIBLE REDIRECT, user will still think he is on page*.php)
Code: Select all
page0.php -> mypage.php?page=0
page1.php -> mypage.php?page=1
page2.php -> mypage.php?page=2
page3.php -> mypage.php?page=3
page4.php -> mypage.php?page=4
page5.php -> mypage.php?page=5
page6.php -> mypage.php?page=6
page7.php -> mypage.php?page=7
page8.php -> mypage.php?page=8
page9.php -> mypage.php?page=9
I suggest you use something like:
Code: Select all
RewriteEngine on
RewriteRule ^pages/(.*).php/$ mypage.php?page=$1
This will make something like this happen:
Code: Select all
/scripts/purchase.php -> mypage.php?page=purchase
/scripts/download.php -> mypage.php?page=download
/scripts/adminlogin.php -> mypage.php?page=adminlogin.php
I hope this helsp you.
Posted: Wed Mar 08, 2006 3:06 pm
by ljCharlie
Thank you so much for the hlep. I still receive the error. I tried just RewriteEngine On and still receive the error. So I guess that means mod_rewrite is not turned on. If this is true, what are my other options if any?
Posted: Wed Mar 08, 2006 3:37 pm
by R4000
It could be a sign that it is disabled.
Your only other bet is to create a php file for every page and whack:
Code: Select all
<?php
$PAGE_NAME = ""; // This can be replaced with some code to auto get it, forgot the code tho.
header("Location: ../mypage.php?page=".$PAGE_NAME);
?>
Posted: Wed Mar 08, 2006 4:03 pm
by feyd
might be worth it to ask your host if they have mod_rewrite on, or if you php supports it, you can interogate Apache yourself:
apache_get_modules()