modx Evo 中基于 url 分段的重定向

发布于 2024-10-14 11:15:00 字数 513 浏览 7 评论 0原文

假设您在 modx Evo

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

中输入了这样的 url ,如果我有一个名为 toamovie 的页面,其父页面名为 < code>reference

但当有人输入该网址时,我希望它执行与

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

等效的操作,或者更重要的是, 我希望结果更像这样,其中 12 是文档

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

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

let's say you have a url like this entered in modx Evo

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

if I have a page called toamovie whose parent is called reference

but when someone enters that url I want it to do the equivalent of this

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

additionally, or more importantly,
I'd like the result to be more like this, where 12 wouls be the id of a document

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

I'm wondering if this is at all possible with modx Evolution.I'm thinking that this should be possible to do with some htaccess magic, well the first part anyway. How could I get a value that the document? This would be quite inaccessible with htaccess, so there would need to be another part to it that could plug into the database and get that value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听不够的曲调 2024-10-21 11:15:00

通过在“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。可能需要一些错误处理。

It should be possible with a custom plugin called on the "OnPageNotFound" event.

<?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]);
}
?>

remember that plugins aren't wrapped in php tags.
also that this script will pass any incorrect urls to zipit.org. Some error handling is probably desireable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文