简体   繁体   English

URL重写将如何与3个参数一起使用?

[英]How the URL-Rewrite will work with 3 Params aswell?

i have build a URL-Routing FrontController in PHP. 我已经在PHP中建立了URL路由FrontController。 All works fine, but now i find a error, if i have more params then 2 it dont works, for example: 一切正常,但现在我发现一个错误,如果我有更多参数,则2不起作用,例如:

This URL works: "www.comelio.com/business-intelligence/anleser/" 该URL起作用: "www.comelio.com/business-intelligence/anleser/"

but this URL dont works: "www.comelio.com/business-intelligence/data-mining/anleser/" 但是此网址不起作用: "www.comelio.com/business-intelligence/data-mining/anleser/"

My Rewrite Rule: 我的重写规则:

RewriteRule ^([\w-]+)/?([\w-]+)/?([\w-]+)/?([\w-]+)? index.php?lang=$1&rubrik=$2&unterrubrik=$3&seite=$4

Here my Routing if-else code: 这是我的路由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";
  }
}

Before i write this code so the second parameter works only, now only the third parameter works, for example now works: "comelio.com/business-intelligence/data-mining/anleser" 在我编写此代码以使第二个参数仅起作用之前,现在只有第三个参数起作用,例如现在起作用: "comelio.com/business-intelligence/data-mining/anleser"

And this dont works: "comelio.com/business-intelligence/anleser" "comelio.com/business-intelligence/anleser""comelio.com/business-intelligence/anleser"

Have a look at the htaccess Tester here (Make sure to add http in the URL field). 在此处查看htaccess测试器 (确保在URL字段中添加http)。

In your Rewrite Condition, you only make the slashed optional. 在“重写条件”中,仅使斜线为可选。 Thus, the rewriter will always split up the request url to match 4 parts. 因此,重写器将始终将请求URL拆分为匹配4个部分。 Try changing your rule to 尝试将规则更改为

RewriteRule ^([\w-]+)/?([\w-]+)?/?([\w-]+)?/?([\w-]+)? index.php?lang=$1&rubrik=$2&unterrubrik=$3&seite=$4

(Note the question marks behind the ([\\w-]+) ) (请注意([\\w-]+)后面的问号)

This will give you 这会给你
http://www.comelio.com/index.php?lang=business-intelligence%26rubrik=data-mining%26unterrubrik=anleser%26seite=

and

http://www.comelio.com/index.php?lang=business-intelligence%26rubrik=anleser%26unterrubrik=%26seite=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM