【发布时间】:2018-05-19 15:41:14
【问题描述】:
我以前问过这样的问题,但由于我仍然找不到答案,所以我会再问一次:-s。
我正在使用这个非常基本的“模板”脚本:
require_once 'core/init.php';
if(empty($_GET['page'])){
header('Location: home');
die();
}
$basePath = dirname(__FILE__) . '/';
$viewPath = $basePath . 'view/';
$view = scandir($viewPath);
foreach($view as $file)
{
if (!is_dir($viewPath . $file))
{
$pages[] = substr($file, 0, strpos($file, '.'));
}
}
if(in_array($_GET['page'], $pages)){
include($viewPath . $_GET['page'] . '.php');
} else{
include($basePath . '404.php');
}
我正在使用这个 htaccess 文件将我的网址从 /base/index.php?page=somepage 重写为 /base/somepage(某个页面是我的模板文件夹中的 .php 文件)
RewriteEngine On
RewriteBase /base/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?page=$1 [L,QSA]
使用 1 个参数它工作得很好,但我的问题是我不知道如何重写第二个参数 /base/profile?user=username(没有 htaccess 文件,这看起来像这样 /base/index.php?page=profile?user=username),我希望它看起来像这样/base/profile/username。
我希望这个问题可以理解:-s
【问题讨论】:
-
刚刚检查...你看到这个post了吗?
-
嘿@AlejandroMontilla,是的,我已经看到了,但是由于我没有使用 Laravel,所以我无法弄清楚:(
-
你应该看到@Zyigh的答案,这是一个非常好的解释。
标签: php .htaccess mod-rewrite url-rewriting