Jump to content

trying to have a single url for different web pages.


Recommended Posts

Actually I wanted to have a index.php

It will get content from a page: http://mysite.com/main.htm

but I want to have links with similar style

like

http://mysite.com/index.php?view=help

it will then fetch help.htm instead of main.htm

 

similarly,

http://mysite.com/index.php?view=aboutus

and then it will fetch aboutus.htm

 

and if the given option is not corrent then it will fetch 404.htm.

 

Thanks for your help.

you can add some error checking and also move your html files to a separate folder to be organized

 

<?php
$_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home';

echo file_get_contents('html/'.$_GET['view'].'.htm');

?>

thanks,

would that work for php files as well?

and what if I want to define certain .html, .php or urls and rest goes to 404.htm

 

you should stick with either htm or html not both... i guess you can pass another variable... there are probably better ways

<?php
$types=array('php','html','link');

$_GET['t']=(in_array($_GET['t'],$types))?$_GET['t']:'html';
$_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home';

switch($_GET['t']){
    case 'html':
        echo file_get_contents('html/'.$_GET['view'].'.htm');
    break;
    case 'php':
        header('location: '.$_GET['view'].'.php');
    break;
    case 'link':
        header('location: '.$_GET['view']);
    break;
}
?>

 

<?php
$types=array('php','html','link');

$_GET['t']=(in_array($_GET['t'],$types))?$_GET['t']:'html';
$_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home';

switch($_GET['t']){
    case 'html':
        echo file_get_contents('html/'.$_GET['view'].'.htm');
    break;
    case 'php':
        echo file_get_contents('http://'.$_SERVER['SERVER_NAME'].'/'.$_GET['view'].'.php');
    break;
    case 'link':
        echo file_get_contents($_GET['view']);
    break;
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.