drl92080 2017-12-21 15:16
浏览 70
已采纳

Joomla SEF自定义组件任务的URL

I am quite new to Joomla! and building a custom component to provide API services. Below is the url to the component function :

http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json

I would like to change it to become :

http://www.example.com/componentA/functionA

Is there any idea I could achieve that?

I tried rewrite on .htaccess for that particular url but Joomla! will redirect it back to index.php.

Also tried installing joomsef by ARTIO but it did not work.

Thanks in Advance!

  • 写回答

1条回答 默认 最新

  • dory4404 2017-12-21 19:19
    关注

    After a few more hours of testing I've solved it. I've added router.php to my component folder with two functions in it "[componentName]BuildRoute" and "[componentName]ParseRoute" to override original function. Refer Joomla! Documentation.

    [componentName]BuildRoute will be the function building SEF or custom URL.
    - This function will return an array where element in it will be concatenate to build the custom URL. - Depends on what you return in the array will determine the URLstructure.
    For eg. :

    http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json

    BuildRoute need to return array("ajax", "functionA");

    and translate into http://www.example.com/component/componentA/ajax/functionA

    [componentName]ParseRoute will be the function to convert your custom URL back to internal URL.

    • This function will input an array where each of the element will be use to determine the internal URL.

    • Then using the parameter to rebuild a return array that map back to internal link

    For Eg. :

    http://www.example.com/component/componentA/ajax/functionA

    ParseRoute parameter will be array("ajax", "functionA")

    ParseRoute needs to return array("task" => "ajax.createPolicyResult", "format"=>"json");

    http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json


    I cant remove the "component" from the URL else it won't work but its OK for me. As the "componentA" is needed as well so that it will call the router.php file in my custom component folder.

    Hope this help =)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料