前端模块中的友好 URL 问题 - Prestashop [英] Friendly URL problem in front module - Prestashop

查看:69
本文介绍了前端模块中的友好 URL 问题 - Prestashop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为在 SEO 和 URL 配置中使用 301 Moved Permanently 选项的网站构建前端模块.Wesbite 使用 Prestashop 1.6.1.9.

I am building a front module for a website that is using 301 Moved Permanently option in SEO and URLs configuration. Wesbite uses Prestashop 1.6.1.9.

在模块中,我像这样定义路由:

In module, I am defining the route like this:

public static $ModuleRoutes = array(
    'module-aacategories-viewmapping-mapping' => array(
        'controller' => 'viewmapping',
        'rule' => 'mappings{/:tree}',
        'keywords' => array(
            'tree' =>        array('regexp' => '[/_a-zA-Z0-9-\pL]*', 'param' => 'tree'),
        ),
        'params' => array(
            'fc' => 'module',
            'module' => 'aacategories',
        )
    )
);

在浏览器地址栏中,当我输入:

In browser address bar, when I enter:

site.local/en/mappings/test-map/first-test

site.local/en/mappings/test-map/first-test

我明白了:

请改用以下网址:

site.local/en/index.php?controller=viewmapping&tree=test-map%2Ffirst-test&module=aacategories

site.local/en/index.php?controller=viewmapping&tree=test-map%2Ffirst-test&module=aacategories

后一个链接给出 404.但是,当我将 &fc=module 附加到 url 时,它会转到所需的页面.

This latter link gives 404. However, when I append &fc=module to the url, it goes to desired page.

问题:

1- 如何强制 Prestashop 路由在末尾附加 &fc=module?

1- How to force Prestashop routing to append &fc=module at the end?

2- 如何将友好的 url 保留在地址栏中而不被重定向?

2- How to keep the friendly url in address bar and not be redirected?

注意:当我将 SEO 和 URL 中的配置更改为 no redirection 时,它会起作用.但这不是prod中需要的配置.

Note: When I change configuration in SEO and URLs to no redirection, then it works. But it is not the configuration needed in prod.

非常感谢您的帮助.提前致谢.

Your help is much appreciated. Thanks in advance.

推荐答案

问题是您正在模块控制器中设置公共属性 $php_self.

The problem is you are setting public property $php_self in your module controller.

您需要删除该属性,以便核心前端控制器不会进行规范重定向.

You need to remove the property so that core front controller does not do a canonical redirect.

执行此操作的代码位于 FrontController.php 第 378 行.

The code that does this is in FrontController.php line 378.

if (!empty($this->page_name)) {
    $page_name = $this->page_name;
} elseif (!empty($this->php_self)) {
    $page_name = $this->php_self;
} elseif (Tools::getValue('fc') == 'module' && $module_name != '' && (Module::getInstanceByName($module_name) instanceof PaymentModule)) {
    $page_name = 'module-payment-submit';
}
// @retrocompatibility Are we in a module ?
elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
    $page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
} else {
    $page_name = Dispatcher::getInstance()->getController();
    $page_name = (preg_match('/^[0-9]/', $page_name) ? 'page_'.$page_name : $page_name);
}

如果您在第 401 行设置了该属性,则执行规范重定向.

And then does a canonical redirect if you set that property on line 401.

if (!empty($this->php_self) && !Tools::getValue('ajax')) {
    $this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
}

这篇关于前端模块中的友好 URL 问题 - Prestashop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆