Mod rewrite 使用Prestashop 1.5.3修改/友好URL
我已经创建了3个自定义页面(控制器、php和tpl文件),并为SEO和URL创建了条目。 所有自定义页面目前都是重复的,并显示相同的内容 我已在blocktopmenu.php中为自定义页面创建了链接:Mod rewrite 使用Prestashop 1.5.3修改/友好URL,mod-rewrite,friendly-url,prestashop,Mod Rewrite,Friendly Url,Prestashop,我已经创建了3个自定义页面(控制器、php和tpl文件),并为SEO和URL创建了条目。 所有自定义页面目前都是重复的,并显示相同的内容 我已在blocktopmenu.php中为自定义页面创建了链接: $this->_menu .= '<li><a href="'.$this->context->link->getPageLink('bHome.php').'">Home</a></li>'.PHP_EOL; $this-
$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('bHome.php').'">Home</a></li>'.PHP_EOL;
$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('bSamples.php').'">Samples</a></li>'.PHP_EOL;
$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('start.php').'">Test</a></li>'.PHP_EOL;
我的另外两页没有翻译:
http://localhost/Shop/index.php?controller=bHome
http://localhost/Shop/index.php?controller=bSamples
有人知道问题是什么吗?< /P> < P>,让我们看看函数GETPaGelink:
public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false)
{
$controller = Tools::strReplaceFirst('.php', '', $controller);
if (!$id_lang)
$id_lang = (int)Context::getContext()->language->id;
if (!is_array($request))
{
// @FIXME html_entity_decode has been added due to '&' => '%3B' ...
$request = html_entity_decode($request);
if ($request_url_encode)
$request = urlencode($request);
parse_str($request, $request);
}
$uri_path = Dispatcher::getInstance()->createUrl($controller, $id_lang, $request);
$url = ($ssl && $this->ssl_enable) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');
return $url;
}
它删除了@romainberger建议的.php
。但在你的情况下并非如此。
接下来,我们深入研究Dispatcher类中的createUrl。我不打算全部粘贴在这里,你不妨自己动手,但是:
public function createUrl($route_id, $id_lang = null, array $params = array(), $force_routes = false, $anchor = '')
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
if (!isset($this->routes[$id_lang][$route_id]))
{
$query = http_build_query($params, '', '&');
$index_link = $this->use_routes ? '' : 'index.php';
return ($route_id == 'index') ? $index_link.(($query) ? '?'.$query : '') : 'index.php?controller='.$route_id.(($query) ? '&'.$query : '').$anchor;
}
我很确定这里就是这种情况,这意味着当前语言中的路由配置不正确。我不知道这是否有影响,但是使用Prestashop 1.5,您不需要在
getPageLink()
方法中添加.php
扩展名。您可以使用b示例
或start
onlyTanks作为您的答案,但不幸的是,这也不起作用。
public function createUrl($route_id, $id_lang = null, array $params = array(), $force_routes = false, $anchor = '')
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
if (!isset($this->routes[$id_lang][$route_id]))
{
$query = http_build_query($params, '', '&');
$index_link = $this->use_routes ? '' : 'index.php';
return ($route_id == 'index') ? $index_link.(($query) ? '?'.$query : '') : 'index.php?controller='.$route_id.(($query) ? '&'.$query : '').$anchor;
}