expressionengine URL重写2.3.1

发布于 2024-12-17 14:12:32 字数 377 浏览 7 评论 0 原文

在 EE 2.2.2 中,我的 htaccess 文件中包含此内容

RewriteRule ^(.*)$ /index.php/view/$1 [L] 

允许我将 domain.com/index.php/view/phone 重写为 domain.com/phone

在 EE 2.3.1 中,这不再有效。问题似乎出在 system\codeigniter\system\core\URI.php 上,我发现这个文件没有什么变化。如果我将 URI.php 替换为 2.2.2 版本,那么它会再次工作。我的问题是发生了什么变化以及如何让它再次发挥作用。

In EE 2.2.2 having this in my htaccess file

RewriteRule ^(.*)$ /index.php/view/$1 [L] 

Allowed me to rewrite domain.com/index.php/view/phone to domain.com/phone.

In EE 2.3.1 this no longer works. The problem seems to be with system\codeigniter\system\core\URI.php and I see few things has changed with this file. If I replace URI.php with the 2.2.2 version then it works again. My question is what has changed and how do I get this to work again.

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

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

发布评论

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

评论(1

墟烟 2024-12-24 14:12:32

更新的答案

经过一段时间的思考(和测试),我想出了一个替代解决方案,它可能适合您更新的 EE 的需求。

假设您的重写规则如下:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

现在,我的建议是让您的 view 模板组成为索引模板组。
view 模板组中的索引模板中,您可以具有以下内容:

{exp:channel:entries channel="view_channel" require_entry="yes"}
{if no_results}
{embed="a_template_group/my_normal_frontpage"}
{/if}
<DOCTYPE html>
<html>
    <head>
        <title>{title}</title>
    </head>
    <body>
        <h1>{title}</h1>
    </body>
</html>

{/exp:channel:entries}

这允许您在不添加其他重写规则的情况下,让访问者转到 http://example.org/phone 并且 view/index 模板将尝试查找条目 ID 标记为“phone”的条目。如果找不到该条目({if no_results} 部分),请嵌入另一个模板。在这种情况下,我假设您想显示某种首页。

这还允许您在 view 模板组下创建普通模板,例如 view/create_entry ,当您转到 http://example.org/create_entry

这应该可以工作 - 并且可以轻松定制以满足您的需求。

Updated answer

After some time with thoughts (and testing) I've come up with an alternate solution, that might fit your need with the updated EE.

Assuming your rewrite rules are like the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Now, my suggestion is to let your view template group be the index template group.
In your index template in the view template group, you could have the following:

{exp:channel:entries channel="view_channel" require_entry="yes"}
{if no_results}
{embed="a_template_group/my_normal_frontpage"}
{/if}
<DOCTYPE html>
<html>
    <head>
        <title>{title}</title>
    </head>
    <body>
        <h1>{title}</h1>
    </body>
</html>

{/exp:channel:entries}

This allows you to, without adding other rewrite rules, have your visitors go to http://example.org/phone and the view/index template will try to find the entry with the entry ID labeled 'phone'. If that entry cannot be found (the {if no_results} part) embed another template. In this case I would assume you'd like to show some sort of frontpage.

This also allows you to, under the view template group, create ordinary templates like view/create_entry which will show up, when you go to http://example.org/create_entry

This should work - and is easy customizable to fit your needs.

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