2017-01-03 41 views
0

我試圖找出其他網站是否有一種方法,我如何在我的PHP頁面中替換?p=page/page。我想從http://localhost/tapromtour.com/?p=tour_discovery更改爲http://localhost/tapromtour.com/tour_discovery。我的主頁上的代碼如下:如何更換?p =頁面/頁面?

<?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">'; 
    } 
?> 

我使用此代碼鏈接頁面。如果有請幫助告訴我該怎麼做,是否有任何方法可以從"localhost/tapromtour.com/?p=tour_discovery"更改爲"localhost/tapromtour.com/tour_discovery"?。由於

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

+1

使用'.htaccess' – Thamilan

+0

你能告訴我如何使用它嗎? –

+2

谷歌.htaccess - >嘗試 - >失敗 - >詢問失敗 – omxv

回答

0

您可以使用此.htaccess規則你的根目錄或者你有你的項目文件我假設你在index.php文件中獲取數據目錄中。

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

創建一個txt文件,將其命名.htaccesshtaccess.txt把這個規則裏面再試試您的網址http://localhost/tapromtour.com/tour_discovery

+0

謝謝。這真的很有幫助。 –

+0

如果被認爲有幫助,您可以通過接受它來認可這是一個答案,所以它會對未來的訪問者更有幫助! –

1

現在我做了阿布舍克古傑爾回答。這是我在我的index.php代碼現在:

<?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">'; 
    } 
?> 

我從echo '<meta http-equiv="refresh" content="0; url=?p=home">';改爲echo '<meta http-equiv="refresh" content="0; url=home">';,使其很好地工作。

+0

沒錯。當我在OP下張貼時,甚至沒有意識到這是在這裏 – Kray

相關問題