使用 Joomla SEF 重写自定义 url

发布于 2024-12-11 20:13:00 字数 825 浏览 0 评论 0原文

我正在尝试在 Joomla! 内部重写一些 url! 1.7 已打开 SEF 功能,但似乎无法弄清楚:

存在以下 SEF URL(菜单项):

website.com/local/amsterdam

我想要的是以下内容:

http://website.com/local/amsterdam/trends (不存在) 渲染 http://website.com/local/amsterdam?show=trends 同时仍显示第一个 URL。

使用 .htaccess 可以进行以下工作(但不显示 SEF URL):

RewriteRule ^local/amsterdam/trends$ index.php?option=com_content&view=article&id=14&Itemid=176&show=trends [L]

但这不是:

RewriteRule ^local/amsterdam/trends$ local/amsterdam?show=trends [L]

我希望找到一个无需使用 id 的解决方案,以便它能够动态呈现所有城市的正确页面。我很感激在 .htaccess 中执行此操作的任何想法以及实现此目的的任何不同解决方案!提前致谢。

I'm trying to wrap my head around rewriting some urls internally in Joomla! 1.7 with SEF features turned on but can't seem to figure it out:

The following SEF URL exists (menu item):

website.com/local/amsterdam

What I would like is the following:

http://website.com/local/amsterdam/trends (non-existant)
to render
http://website.com/local/amsterdam?show=trends
while still displaying the first URL.

Working with .htaccess the following works (but doesn't show SEF URL):

RewriteRule ^local/amsterdam/trends$ index.php?option=com_content&view=article&id=14&Itemid=176&show=trends [L]

But this doesn't:

RewriteRule ^local/amsterdam/trends$ local/amsterdam?show=trends [L]

I'm hoping to find a solution without having to use an id so that it will dynamically render the correct page for all cities. I'ld appreciate any thoughts on doing this in .htaccess as well as any different solutions to achieve this! Thanks in advance.

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

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

发布评论

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

评论(1

我早已燃尽 2024-12-18 20:13:00

虽然我最初是在寻找 mod-rewrite 解决方案,但我已经找到了一种通过修改(核心)Joomla! 来实现相同目标的方法!路由器。

在 include/router.php 的第 47 行之后:

$path = substr_replace($path, '', 0, strlen(JURI::base(true)));

我添加了以下内容:

$subpages = array("trends","other"); //Add URL segments you want to reroute
foreach ($subpages as $subpage):            
     if (strstr($path, "/".$subpage)) :
          $path = str_replace("/".$subpage, "", $path);
          $vars['show'] = $subpage;
     endif;
endforeach;

现在加载 http:// www.website.com/local/amsterdam/trends,此 URL 在页面 http://www.website.com/local/amsterdam 实际上加载了 ?show=trends 参数。

对我来说,即使修改了核心文件,这也是比使用 mod-rewrite 更灵活的解决方案。您可能想要使用一些条件语句来仅在某些条件下运行此代码。希望有帮助。

Although I was initially searching for a mod-rewrite solution I have figured out a way to achieve the same by modifying the (core) Joomla! router.

On line 47 of includes/router.php after:

$path = substr_replace($path, '', 0, strlen(JURI::base(true)));

I added the following:

$subpages = array("trends","other"); //Add URL segments you want to reroute
foreach ($subpages as $subpage):            
     if (strstr($path, "/".$subpage)) :
          $path = str_replace("/".$subpage, "", $path);
          $vars['show'] = $subpage;
     endif;
endforeach;

Now when loading http://www.website.com/local/amsterdam/trends, this URL is displayed while the page http://www.website.com/local/amsterdam is actually loaded with the ?show=trends parameter.

For me this a more flexible solution than using mod-rewrite even though a core file is modified. You might want to use some conditional statements to only run this code in certain conditions. Hope it helps.

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