0

I've wrote function in php

function siteContent() {
    $path = array();

    $strDefaultPath = '/sites/';

    $_SERVER['PATH_INFO'] = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : $strDefaultPath;

    $path = explode( '/', substr( $_SERVER['PATH_INFO'], 1) );

    if(file_exists('/'.$path['0'].'.php')) {
        require_once('/'.$path['0'].'.php');
    } else {
        require_once('sites/main.php');
    }
}

it doesn't work

in menu links looks like this http://site.com/subsite/ but path to the files with content of subsites looks likt this public_html/sites/subsite.php

can i rewrite url with this function or

how can i rewrite or build that urls in php only

i'm beginnier in php

arclite
  • 528
  • 1
  • 6
  • 23
  • Is there any reason you don't want to use a .htaccess file? If you are using apache then it's supported. – Devator May 03 '12 at 09:40
  • I'm not really sure what you're trying to achieve with your code... `require` will not change the URL. As far as I know there is no way to rewrite URLs using PHP. – nico May 03 '12 at 09:43
  • i've got contract with hoster wich doesn't allow to use htaccess – arclite May 03 '12 at 09:43
  • 1
    In your position I would change hosting provider.. I don't know even one provider witch would disallow that.. – Vytautas May 03 '12 at 10:49
  • this isn't that simple and for about 23 moths i've got to use this provider :/ – arclite May 04 '12 at 09:06

1 Answers1

1

If you work with Apache, the best way is to use a .htaccess file to make URL rewriting. http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

URL Rewriting for Beginners

Julien
  • 3,509
  • 20
  • 35