PDA

View Full Version : PHP re-direction?



skidpanda
May 10th, 2004, 06:44 AM
Hi,

I'm making a promotion site for bands in Scotland, and I want to give every band that has submitted information to have a profile.

Here is a profile http://www.topofthejocks.co.uk/bands/myband.php?band=small%20enclosed%20area <the data changes depending on the bands name.

What I need is instead of having that long address which will be hard to remember.. is to have it topofthejocks.co.uk/bandname

Can anyone tell me how I can make topofthejocks.co.uk/bandname point to http://www.topofthejocks.co.uk/bands/myband.php?band=bandname

I need it .co.uk/bandname so its easier for bands to remember their address, and I also dont want my root directory getting full of band profiles. All the data is pulled from a MYSQL database.

Any help would be greatly appreciated..

Thanks alot

T-O
May 10th, 2004, 11:29 AM
make a .htaccess file with...

exsample:
"Redirect /search http://www.domain.com/actions/search.php"
to redirect.... http://www.domain.com/search
to http://www.domain.com/actions/search.php

skidpanda
May 10th, 2004, 04:25 PM
Thanks for the reply..

I dont want to edit the htaccess file though everytime a new band adds their information to the site.
Basically the band signs up, i approve the band via admin, the band info gets stored in the database. The band gets a profile. The profile needs to be domainname.com/bandname.. not a long php=bandname script address.

So every /bandname URL links to the same profile but populates it with different info.. its hard to explain.. doh

thanks anyway!

kill.robot.kill
May 11th, 2004, 01:31 PM
mp3.com used to work that way, so I'm thinking there is a better way, I doubt they had a grunt worker updating the file everytime a band signed up.

λ
May 11th, 2004, 01:59 PM
You can edit .htaccess files by PHP ;)

skidpanda
May 11th, 2004, 04:31 PM
Hi, got any more info on PHP editing that file?

Hans Kilian
May 11th, 2004, 05:50 PM
You could do it by writing a custom handler for 404 (not found) errors (if your Apache server allows you to do that).

Then add this line to your .htaccess file
ErrorDocument 404 /custom404page.php

And write code like this in custom404page.php:


<?php
if ($_SERVER['REDIRECT_URL'] == '/bandname') {
// Redirect the user when the URL is for a known band name
header("Location: http://www.topofthejocks.co.uk/bands/myband.php?band=small%20enclosed%20area");
} else {
// Write a custom 404 page when the band name wasen't found
header("HTTP/1.0 404 Not Found");
}
?>


Of course you should get the band names from your database instead of hard coding them in the script.

The right way to do it is to use mod_rewrite though. But that requires that you have full access to the Apache server.