Gustavo Campos Gustavo Campos - 3 months ago 5x
Ajax Question

how to redirect the page analyzing url typed?

I need a page that when I load it check out the link typed for example:

if it finds certain number it redirects to another link for example:

redirects to news

How can I do this and what technology should I use?


First off, your syntax for GET variables is a little off. I assume you mean starting URLs of or something similar? Because is bad syntax.

I'm assuming we're using GET variables as described above in my answer:

The simplest way to do this would be to just set the location header in PHP:

if(array_key_exists("redirect", $_GET)){
    #set header to redirect to new location
    header("Location: /news/" . $_GET["redirect"] . ".php");
    #don't let the page do anything else
    #do something if the GET variable doesn't exist

Note that this way introduces a few security vulnerabilities, so you might want to do something more advanced (such as intval the GET variable so that they can't inject a script into your variable, or just addslashes() to the GET variable value).