?
Solved

Creating instant URL redirects using PHP without editing htaccess file

Posted on 2006-03-29
3
Medium Priority
?
763 Views
Last Modified: 2008-01-09
Hi. We're LearnOutLoud.com and we're looking to create instant URL redirects using our new tool TeachOutLoud (www.teachoutloud.com) which allows users to publish their own audio and video learning content. We want to create redirects for our authors to their author pages on the fly so if their name was Mark Twain there's a field in our system unto which they can type in their redirect to be www.learnoutloud.com/marktwain and this URL would redirect to their author page which is something like: http://www.learnoutloud.com/Resources/Authors-and-Narrators/Mark-Twain/225 (a rewritten PHP URL).

Currently we're creating these redirects manually through cPanel on the back end and it's a pain. And our programmers could do it through auto-editing the htaccess file but that is dangerous as if we corrupt that file the whole site goes down. So we'd like to come up with another solution for somehow creating these redirects. They can create ones that are built onto another level like a redirect off a php pages, but we want to make it so it's right off our URL www.learnoutloud.com/....

This is for marketing purposes for our teachers and authors and for ease of access to their pages. Like MySpace does it: www.myspace.com/tom. We can't figure out a safe way to do it, so we're looking for some one that has a solution.
0
Comment
Question by:jpb123
2 Comments
 
LVL 8

Expert Comment

by:kebabs
ID: 16319968
You don't have a solution then...
You could use the "location" header to immediately process the "author page" on the server side like so:

<?php
header("Location: /Resources/Authors-and-Narrators/Mark-Twain/225");
?>

Just to let you know, editing .htaccess is not dangerous for an experienced developer. And anyone should immediately test the site after any modification to .htaccess and if the site did "break" they could roll back to the previous .htaccess file. I still recommend .htaccess
0
 
LVL 2

Accepted Solution

by:
syrma earned 1000 total points
ID: 16322347
This is what I have done in the past, please take a look if it can work for your situation.

The user is typing  www.learnoutloud.com/marktwain

There is no such real url, the user is send to the 404 error page.
You change this page with a php one, lets say not_found.php

in the not_found.php set something like this.
$author_name=substr('/', '', $_SERVER["REDIRECT_URL"];

$sql="SELECT url FROM authors WHERE author_name = '{$author_name}'";

if ($the_author_is_found, have the url){
 header("HTTP/1.0 200 OK");
 header("Location: ".$url);
}
else {
      header("HTTP/1.0 404 Not Found");
      //do something here, display error page message
}

so this worked for me, but you need to have some way to retrieve the url of the authors home page just knowing let's say "marktwain"
you might have url like this:  http://www.learnoutloud.com/Resources/Authors-and-Narrators/authors_home_pages?author_id=225
I don't know how you form this url  http://www.learnoutloud.com/Resources/Authors-and-Narrators/Mark-Twain/225
but if it follows some logic you should be able redirect to this url using the same logic.

hope this helps :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question