【问题标题】:url segments based redirect in modx Evo在 modx Evo 中基于 url 段的重定向
【发布时间】:2011-01-26 06:03:23
【问题描述】:

假设您在 modx Evo 中输入了这样的网址

www.zipit.com.org/reference/toamovie/

如果我有一个名为 toamovie 的页面,其父页面名为 reference

但是当有人输入该网址时,我希望它执行与此等效的操作

www.zipit.com.org/reference.html?myvar=toamovie

此外,或更重要的是, 我希望结果更像这样,12 将是文档的 id

`www.zipit.com.org/reference.html?myid=12'

我想知道 modx Evolution 是否有可能。我认为这应该与一些 htaccess 魔法有关,无论如何都是第一部分。我怎样才能得到文件的价值?这对于 htaccess 来说是完全无法访问的,因此需要有另一部分可以插入数据库并获取该值。

【问题讨论】:

    标签: .htaccess uri modx modx-evolution


    【解决方案1】:

    在“OnPageNotFound”事件上调用自定义插件应该是可能的。

    <?php
    $url = $_SERVER['REQUEST_URI']; //get the url        
    //split the url into pieces and remove empty values
    $pieces = array_filter(explode('/', $url));
    
    //reset the array keys
    $temp = array();
    foreach ($pieces as $piece) {
        $temp[] = $piece;
    }
    $pieces = $temp;
    
    //basic checking of the url
    if (count($pieces) == 2) {
        $modx->sendRedirect('http://www.zipit.org/' . $pieces[0]  .".html?myid=" . $pieces[1]);
    }
    ?>
    

    请记住,插件不包含在 php 标签中。 此外,该脚本会将任何不正确的 url 传递给 zipit.org。一些错误处理可能是可取的。

    【讨论】:

      猜你喜欢
      • 2012-10-11
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 2011-06-23
      相关资源
      最近更新 更多