【问题标题】:Get a link in Joomla without an alias?在没有别名的情况下在 Joomla 中获取链接?
【发布时间】:2012-02-03 17:20:58
【问题描述】:

在 Joomla 1.7 上,Joomla 允许在别名中使用逗号。为安全起见,在 URL 中带有逗号的页面上出现 Mod_security 404。

Gavick News Show Pro 是一个用于在主页上列出最新消息的模块。它创建到内部页面的链接包括带有逗号的别名,我们需要去掉这些别名。

在 Gavick 代码中,它以这种方式获取链接:

$link = ($news_id !== 0) ? JRoute::_(ContentHelperRoute::getArticleRoute($news_id, $news_cid)) : JRoute::_('index.php?option=com_user&view=login');

这会产生一个链接,例如:

http://example.com/index.php?option=com_content&view=article&id=655:test,ting-here&catid=22:112th-news&Itemid=130

请注意,此站点上未启用 SEF,并且出于安全原因也无法启用。希望有人能够帮助解决我们的问题,而不是讨论我们的特定安全要求。

除了 JRoute 之外,还有其他方法可以在标题中不包含这些别名吗?示例代码会很棒。谢谢!

注意简化,这段代码总是做同样的事情:

$link = JRoute::_(ContentHelperRoute::getArticleRoute($news_id, $news_cid));

【问题讨论】:

    标签: php joomla


    【解决方案1】:

    如果没有使用 SEF,则不需要通过 JRoute。 JRoute 的重点是 SEF URL。

    您将代码更改为:

    //Non SEF link
    $ns_menuItemId = JSite::getMenu()->getActive();
    $ns_link = "/index.php?option=com_content&view=article&id=$news_id&catid=$news_cid&itemid=$nbs_menuItemId";
    $link = ($news_id !== 0) ? $ns_link : JRoute::_('index.php?option=com_user&view=login');
    

    【讨论】:

    • 抱歉不起作用。他们仍然通过您的版本。
    • 你能告诉我更多关于它是如何工作的细节吗?我在我的 1.7 开发安装中使用此 url 跟踪了这一点:http://j16ref.site/index.php?option=com_content&view=article&id=1&catid=1 并在没有任何别名被拉起的情况下完成了它。
    • 确定你想要什么细节?使用您的代码并单击模块为我在标题中随机输入的文章生成的链接时,我得到以下 URL:index.php?option=com_content&view=article&id=657:te`~-$-^ -_-{}-,-st&catid=22:112th-news&itemid= 文章和类别别名仍然出现。
    • 如果我把代码放回原来的位置,它会产生这个链接:index.php?option=com_content&view=article&id=657:te~-$-^-_-{}-,-st&catid=22:112th-news&Itemid=130 (And to note, the title of the test article is: "Te~!@#$%^&*()_ +=-[]\{}|;':",./?st"
    • 所以,我们需要查看更多代码,必须通过 JRoute 传递 $link 以更改我的代码创建的直接链接。
    猜你喜欢
    • 2011-05-16
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    • 2013-05-23
    • 2012-10-05
    • 1970-01-01
    相关资源
    最近更新 更多