Thank you so much for your time and piece of code,
I’m getting Not Found (#404) error when my url looks like this: websted/indeks
but it is okay with site/index.
Here is what I have tried:
In frontend\config/main.php
'urlManager' => [
'baseUrl' => $baseUrl,
'class' => 'frontend\components\CustomUrlRule',
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
],
and in frontend\components\CustomUrlRule
<?php
namespace frontend\components;
use Yii;
use yii\web\UrlManager;
class CustomUrlRule extends UrlManager
{
public function parseRequest($request)
{
if ($this->enablePrettyUrl) {
/* @var $rule UrlRule */
foreach ($this->rules as $rule) {
if (($result = $rule->parseRequest($this, $request)) !== false) {
$routeParts = explode('/', $result[0]);
if (isset($routeParts[0]) && !empty($this->languageControllers[$this->language])) {
foreach ($this->languageControllers[$this->language] as $default => $localized) {
if ($localized == $routeParts[0]) {
$routeParts[0] = $default;
break;
}
}
}
if (isset($routeParts[1]) && !empty($this->languageActions[$this->language])) {
foreach ($this->languageActions[$this->language] as $default => $localized) {
if ($localized == $routeParts[1]) {
$routeParts[1] = $default;
break;
}
}
}
$result[0] = implode('/', $routeParts);
return $result;
}
}
if ($this->enableStrictParsing) {
return false;
}
Yii::trace('No matching URL rules. Using default URL parsing logic.', __METHOD__);
$suffix = (string) $this->suffix;
$pathInfo = $request->getPathInfo();
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($this->suffix);
if (substr_compare($pathInfo, $this->suffix, -$n, $n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
return false;
}
} else {
// suffix doesn't match
return false;
}
}
return [$pathInfo, []];
} else {
Yii::trace('Pretty URL not enabled. Using default URL parsing logic.', __METHOD__);
$route = $request->getQueryParam($this->routeParam, '');
if (is_array($route)) {
$route = '';
}
return [(string) $route, []];
}
}
}
Also please let me know, Is my including of CustomUrlRule class is ok or I need to move somewhere else?
Edit:
This condition is not getting true:
if (($result = $rule->parseRequest($this, $request)) !== false)