views:

16

answers:

1

Hi,

This is a noob question I belieive, in a content management system as well as several other types of sites that work on submissions, once you submit a URL in a URL shortening website for instance, how do you use PHP to redirect to the appropriate URL without a 404 or without using an htaccess.

Based on what I've found in simple url shortening scripts online, an htaccess is always used to redirect 404s to a PHP file which process the URL and goto the specific page, how do you do this without an htaccess?

Another example would be any blog software, once you submit a post, if you goto the specific URL it retrieves the appropriate post without the use of an htaccess.

I hope I'm being clear, thanks.

A: 

You are talking about two different concepts here. One is "url rewriting" the other is "redirection".

Url rewriting is the process of transforming one URL into another, and it may involve or not redirection. This happens server-side, before PHP kicks in. In fact, PHP is not aware of anything. This is performed as htaccess directives. What you obtain is usually the transformation of a complex nested url into a simple url with query.

For example: /blog/2010/10/30 rewritten to blog.php?year=2010&month=10&day=30

This is a beautification, in the sense that PHP responds to the second URL, and you could skip entirely the url rewriting, which is just for the sake of search engines and URL usability.

All of this happens before PHP starts. Then PHP could make its own redirections, and this is done using a call to header("Location: ..."), or a redirection through javascript or as html meta header.

None of this involves any 404.

Palantir