解決!
首先,我知道我可以使用「?page = ...」,但我不喜歡那個變量在我的URL中。現在經過一些搜索後,我發現一個網站使用$ _GET ['page']而不在URL中顯示「?page =」。
但是我在代碼中掙扎了一番。我似乎無法獲得此代碼的工作。我知道它適用於其他網站,但不適用於我的網站。我似乎無法找到它在其他網站上的工作原理。
這是菜單代碼:
<li><a href="index.php">Home</a></li>
<li><a href="even_voorstellen">Even voorstellen</a></li>
<li><a href="de_kennismaking">De kennismaking</a></li>
,這是PHP代碼:
$sExpressie = "(http:|ftp:|shttp:|www.|.php|.pl|.cgi|.asp|index.php)";
if(isset($_GET['pagina']) && eregi($sExpressie,$_GET['pagina']))
{
include("pages/home.php");
}
else
{
if(isset($_GET['pagina']) && file_exists('Pages/' . $_GET['pagina'] . ".php"))
{
include('pages/' . $_GET['pagina'] . ".php");
}
else
{
include("pages/home.php");
}
}
我不明白這個代碼是如何工作的。在我的網站中,「$ GET ['pagina']」永遠不會被填滿,這是合乎邏輯的。但是如何在其他網站上填寫?
非常感謝大家! 解決方案:
以下內容添加到您的.htaccess文件:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ pages/$1.php [NC,L]
閱讀'.htaccess' – AbraCadaver 2015-02-10 16:40:34
正如@AbraCadaver所說,.htaccess是你想要的,但是當你在它的時候:[閱讀PHP文檔](http://php.net/eregi)。 'ereg'和'eregi'已被_deprecated_(並已使用多年),請使用'preg_ *'來代替 – 2015-02-10 16:41:52
Wordpress可以像這樣工作,你可以在那裏看看。 – 2015-02-10 16:43:01