简体   繁体   中英

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

i have build a URL-Routing FrontController in PHP. All works fine, but now i find a error, if i have more params then 2 it dont works, for example:

This URL works: "www.comelio.com/business-intelligence/anleser/"

but this URL dont works: "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($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"

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

Have a look at the htaccess Tester here (Make sure to add http in the URL field).

In your Rewrite Condition, you only make the slashed optional. Thus, the rewriter will always split up the request url to match 4 parts. 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-]+) )

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=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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