为什么不在 .htaccess 中使用它
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule
^(.*)/?$ index.php?page=$1 [L]
</IfModule>
然后在您的 index.php 中返回相应的页面:
# SELECT WHICH PAGE TO DISPLAY
function getPage($showPage) {
$modules = array(#never name the slugs as same as the php pages
'/sign-in/i' => 'register.php',
'/signout/i' => 'logout.php',
'/staff/i' => 'admin.php',
'/products/i' => 'blank.php',
);
foreach ($modules as $slug=>$phpmodule) {
if(preg_match($slug, $showPage)) {
return $phpmodule;
}
}
return 'blank.php';#in case module not found display 404 page
}
if (isset($_GET['page'])) {
require_once (getPage($_GET['page'])); #include the appropriate module file
}
有很多方法可以做到。我希望这能让您知道从哪里开始,如果我的回答对您有用,请投票或接受答案。