我已经在php中构建了一个URL路由前孔。一切都很好,但是现在我发现一个错误,如果我有更多参数,则2不起作用,例如:
此URL有效: "www.comelio.com/business-intelligence/anleser/"
但是此URL不起作用: "www.comelio.com/business-intelligence/data-mining/anleser/"
我的重写规则:
RewriteRule ^([w-]+)/?([w-]+)/?([w-]+)/?([w-]+)? index.php?lang=$1&rubrik=$2&unterrubrik=$3&seite=$4
在这里我的路由if-else代码:
if($seite == null) {
$filename = "{$rubrik}.html";
$xdmvalue = $saxonProc->createAtomicValue($filename);
$xsltProc->setParameter("articlePfad", $xdmvalue);
if(in_array($filename, $filelist)) {
$xmlFile = $dir . "/" . $filename;
$xsltProc->setSourceFromFile($xmlFile);
} else {
echo "404";
}
} else if(isset($seite) && isset($rubrik)){
$filename = "{$rubrik}_{$seite}.html";
$xdmvalue = $saxonProc->createAtomicValue($filename);
$xsltProc->setParameter("articlePfad", $xdmvalue);
if(in_array($filename, $filelist)) {
$xmlFile = $dir . "/" . $filename;
$xsltProc->setSourceFromFile($xmlFile);
} else {
echo "404";
}
} else if(isset($seite) && isset($rubrik) && ($unterrubrik)){
$filename = "{$rubrik}_{$unterrubrik}_{$seite}.html";
$xdmvalue = $saxonProc->createAtomicValue($filename);
$xsltProc->setParameter("articlePfad", $xdmvalue);
if(in_array($filename, $filelist)) {
$xmlFile = $dir . "/" . $filename;
$xsltProc->setSourceFromFile($xmlFile);
} else {
echo "404";
}
}
在我编写此代码之前,第二个参数仅有效,现在仅第三个参数起作用,例如现在起作用: "comelio.com/business-intelligence/data-mining/anleser"
这不起作用: "comelio.com/business-intelligence/anleser"
在此处查看HTACCESS测试仪(请确保在URL字段中添加HTTP(。
在您的重写条件下,您只能进行砍伐的可选。因此,重写器将始终将请求URL分开以匹配4个零件。尝试将您的规则更改为
RewriteRule ^([w-]+)/?([w-]+)?/?([w-]+)?/?([w-]+)? index.php?lang=$1&rubrik=$2&unterrubrik=$3&seite=$4
(请注意([w-]+)
背后的问号(
这会给你
http://www.comelio.com/index.php?lang=business-intelligence%26rubrik=data-mining%26unterrubrik=anleser%26seite=
和
http://www.comelio.com/index.php?lang=business-intelligence%26rubrik=anleser%26unterrubrik=%26seite=