开发者

request_uri and array those kind of stuff

I have a code which I need help on.

    if ($_SERVER['REQUEST_URI'] == '/testmore/' || $_SERVER['REQUEST_URI'] == '/testmore/home') { $_SERVER['REQUEST_URI'] = '/testmore/index'; }

    echo $_SERVER['REQUEST_URI']; echo '<br>';


    $page = $_SERVER['REQUEST_URI'];

    function dostuff($pagesC) { echo 'yes!<br>'; echo $pagesC.'<br>'; }


    $pageArray = Array('index', 'login'); 

$directory = '/testm开发者_开发百科ore/'; // Directory if in one. Otherwise, leave it as '/'.  

    $uriArray = explode('/', strstr($_SERVER['REQUEST_URI'], $directory));
      if (in_array($uriArray[0], $pageArray)) {
        dostuff($uriArray[0]); } else {
        echo '404'; }

This uses URI requests and it makes it from http://link.com/index.php?page=$VARIABLE to http://link.com/variable

I have all the .htaccess done and working which wont be a problem. The problem is that when I type http://link.com/testmore/index it wont show that specified page, but instead a 404 page.


You should not have to do any work in the PHP page. The reason your pages aren't working is because your .htaccess code is incorrect. Try this:

RewriteRule ^(.*?)/(.*?)$ index.php?page=$1&sub=$2 [L]
RewriteRule ^(.*?)$ index.php?page=$1 [L]

The above will mask redirect http://link.com/testmore/index to http://link.com/index.php?page=testmore&sub=index. It will also redirect http://link.com/variable to http://link.com/index.php?page=variable.

$uriArray = explode('/', $_SERVER['REQUEST_URI']);
if (in_array($uriArray[1], $pageArray)){
     dostuff($uriArray[1]);
else
     echo '404';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜