0

我已经在 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');
    }
}

它不起作用

在菜单链接中看起来像这样http://site.com/subsite/ 但是包含子站点内容的文件的路径看起来像这样 public_html/sites/subsite.php

我可以用这个函数重写 url 或

我如何仅在 php 中重写或构建该 url

我是 php 的初学者

4

1 回答 1

1

如果您使用 Apache,最好的方法是使用 .htaccess 文件进行 URL 重写。 http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

初学者的 URL 重写

于 2012-05-03T09:42:10.060 回答