0

I have tried to find out in other websites whether there is a way on how to I replace ?p=page to /page in my PHP page. I want to change from http://localhost/tapromtour.com/?p=tour_discovery to http://localhost/tapromtour.com/tour_discovery. My code in my homepage is as below:

<?php
    if (isset($_GET["p"])){
        $ext =".php";
        $file_name = $_GET["p"];
        $file = "view/".$file_name.$ext;
        if (file_exists($file)){
        include $file;
        }else{
        echo 'no file found';
        }
    }else{
        echo '<meta http-equiv="refresh" content="0; url=?p=home">';
    }
?>

I use this code to link from page to page. Is there any ways to change from "localhost/tapromtour.com/?p=tour_discovery" to "localhost/tapromtour.com/tour_discovery"? if there is please help tell me how to do it. Thanks

http://localhost/tapromtour.com/?p=tour_discovery http://localhost/tapromtour.com/tour_discovery

2 Answers2

1

Now I did it as what Abhishek gurjar answered. This is my code in my index.php now:

<?php
    if (isset($_GET["p"])){
        $ext =".php";
        $file_name = $_GET["p"];
        $file = "view/".$file_name.$ext;
        if (file_exists($file)){
        include $file;
        }else{
        echo 'no file found';
        }
    }else{
        echo '<meta http-equiv="refresh" content="0; url=home">';
    }
?>

I changed from echo '<meta http-equiv="refresh" content="0; url=?p=home">'; to echo '<meta http-equiv="refresh" content="0; url=home">'; so that it work very well.

0

You can use this .htaccess rule inside your root directory or directory where you having your project files i am assuming you are getting the data in index.php file.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?p=$1 [QSA,L]

Create a txt file, name it .htaccess not htaccess.txt put this rule inside it then try your url http://localhost/tapromtour.com/tour_discovery.

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45