How to create a page in PHP

I’m using a php script, where all pages end in "php, for example

Can a page be created to show just ?

If so, how, please? Thanks

Yes. It’s done with mod_rewrite,

First, create index.php script, which will look like this:

    $action = (isset($_GET['action'])) ? urldecode($_GET['action']) : 'home'; 

    $content = '';

    switch ($action) {
        case 'home':
            $content = 'Hello, I am home page';
        case 'contact':
            $content = 'Hello, I am contact page';
            $content = 'Page not found';

    echo $content;

Add .htacces like this:

RewriteEngine on
RewriteRule ^([A-Za-z]+)/$ /index.php?action=$1 

And then try visiting these URIs:


That’s a super simple example so don’t use that in production.

This is completely untested so there might be some errors.

Correct .htaccess (I can’t edit the above post anymore):

RewriteEngine on
RewriteRule ^([^/\\.]+)/?$ index.php?action=$1 [L]

For further reference, please see our Apache Configuration which is the place for [url=“”]mod_rewrite resources and articles such as [url=“”]Learn Apache mod_rewrite: 13 Real-world Examples

Thanks for the replies. However, I’m using an existing php script. In this script you need to add to page.php to add a page. But when you add a page the browser title looks like this, for example:

And I’d like to add a page that looks something like this:

Can you help me? Thanks. Here’s the code for page.php:

include_once ("classes/config.php");
include_once ('classes/menu.php');
include_once ('classes/sessions.php');

$page = $_GET['page'];

//use this script to load various generic pages  (e.g. about us, terms etc)

switch ($page){
	case 1:
	$which_page = 'generic_aboutus.htm';
	case 2:
    $which_page = 'generic_contactus.htm';
    case 3:
    $which_page = 'generic_terms.htm';
    case 4:
    $which_page = 'generic_advertise.htm';
    header( 'Location: index.php' ) ;
$template = "templates/main.htm";
$inner_template1 = "templates/$which_page";//middle of page
$TBS = new clsTinyButStrong;
$TBS->NoErr = true;// no more error message displayed.
$TBS->MergeBlock('mp', $recent);
$TBS->MergeBlock('blkfeatured', $result_featured);
$TBS->Render = TBS_OUTPUT;

PHP cannot interpret the address in the way that you require.
It is the web server (commonly an Apache server) that needs to be configured using mod_rewrite, so that requests to the nice address become internally redirected to the querystring address.

The greatest extent of change to your PHP code, is changing the web page links to point instead to the nicer looking address links.
Before you can do that, you need your server to rewrite those clean address links so that they redirect to their appropriate PHP pages.

I refer you back to our Apache Configuration forum, and their [url=“”]mod_rewrite resources sticky thread.

… which is where I would refer you, too, as I have the CORRECT mod_rewrite code (not a PHP kludge) for exactly what you’re asking for (also linked in my signature).