【问题标题】:Joomla - create custom rewrite rulesJoomla - 创建自定义重写规则
【发布时间】:2015-04-22 21:24:39
【问题描述】:

我开发了一个类似于目录的 Joomla 网站。人们在站点中有他们的个人资料,我创建了一个名为 com_profile 的组件来在传递 id 时显示他们的个人资料。因此,对于以下 URL,它现在正在显示配置文件。

http:///index.php?option=com_profile&id=100

我需要更改网址,因此当用户键入“http:///service_providers/100”时,它将显示个人资料。

我该怎么做?我在 htaccess 中尝试了不同的方法,但没有任何帮助。 :(

【问题讨论】:

    标签: php .htaccess mod-rewrite components joomla3.0


    【解决方案1】:

    将此添加到您的 apache 配置或 htaccess 文件中:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^service_providers/([a-zA-Z0-9-z\-]+)$ index.php?option=com_profile&id=$1
    

    确保启用了 modrewrite。如果不是,请通过 cli 输入 a2en modrewrite 来启用它

    【讨论】:

    • 谢谢。但它不起作用。以前当我输入 url 时,它会转到 404 页面,但现在它不会转到 404。而是显示主页。我输入了这个网址 /service_providers/193。它仍然显示主页。当我输入 /option=com_profile&id=193 时,它显示的是正确的配置文件。
    • 对不起。它似乎工作。我认为我的组件中的一些限制重定向回主页。非常感谢。我会检查并修复它。