Redirect page through the link typed in the url

Asked

Viewed 470 times

-1

I need a page that when I load it check the link typed for example : www.test.com/myphp.php=10 if it finds a certain number it redirects to another page , for example : found www.test.com/myphp.php=10 redirects to www.test.com/news/10.php. How can I do this and what technology I should use?

  • It’s just a case or do you want to redirect all the urls to news/.

1 answer

0


<?php
/**
 * User: rafaelphp
 * Date: 22/07/16
 * Time: 05:20 PM
 * File: index.php
 */

# exemplo basico - existem outras maneiras de fazer o que vc esta dizendo
# inclusive atraves do arquivo .htaccess(apache)

#vc deve validar dados vindo por get
$param = array();
$param['page'] = ( isset( $_GET['page'] ) ) ? $_GET['page'] : null ;

#vc pode validar as url procurando se o arquivo existe ou em uma funcao feita por vc
#isso pode ser feito antes da funcao 'switch; ou dentro do laco 'case'
$param['redir_url'] = "http://www.mydomain.com/news/";
$param['go']        = $param['redir_url'] . $param['page'] . ".php";

switch ($param['page'])
{
    case "10":
        header( "Location: " . $param['go'] );

        break;

    case "11":
        header( "Location: " . $param['go']);
        break;

    default:
        die("Error... pagina nao existe");
        break;
}
?>
  • was worth the help friend but some guys answered here what I needed http://stackoverflow.com/questions/38531569/how-to-redirect-the-page-analyzing-url-typed so here it was much easier

Browser other questions tagged

You are not signed in. Login or sign up in order to post.