Answer the question
In order to leave comments, you need to log in
How to configure routing depending on parameters in UrlManager?
In the texts of articles on the site there are links like index.php?option=com_content&view=article&id=1
How to register in UrlManager so that when such links are opened, a specific controller is opened?
For example, if view = article, then article/view is opened and the id parameter is passed, and if view = category, then category/view
'rules' => [
'index.php?option=com_content&view=article' = 'article/view',
]
redirects everything to index.php, and if you replace index.php with files.php, it gives 404.
Answer the question
In order to leave comments, you need to log in
*** Option 1 *** - create a custom rule for the URL.
<?php
namespace app\components;
use yii\web\UrlRuleInterface;
use yii\base\Object;
class JoomlaUrlRule extends Object implements UrlRuleInterface
{
public function createUrl($manager, $route, $params)
{
return false;
}
public function parseRequest($manager, $request)
{
$it_joomla_url = $request->getPathInfo()===''
&& $request->getQueryParam('option')==='com_content';
if (!it_joomla_url) {
return false;
}
$view = $request->getQueryParam('view');
if (empty($view)) {
return false;
}
return ["$view/view", $request->queryParams];
}
}
[
'components' => [
'urlManager' => [
// ...
'rules' => [
['class' => 'app\components\JoomlaUrlRule'],
// ...
],
],
],
]
RewriteCond %{THE_REQUEST} index.php [NC]
RewriteCond %{QUERY_STRING} option=com_content [NC]
RewriteCond %{QUERY_STRING} view=category [NC]
RewriteRule (.*) /category/view/ [L,R=301,QSA]
RewriteCond %{THE_REQUEST} index.php [NC]
RewriteCond %{QUERY_STRING} option=com_content [NC]
RewriteCond %{QUERY_STRING} view=article [NC]
RewriteRule (.*) /article/view/ [L,R=301,QSA]
RewriteCond %{THE_REQUEST} index.php [NC]
RewriteCond %{QUERY_STRING} option=com_content [NC]
RewriteCond %{QUERY_STRING} view=category [NC]
RewriteCond %{QUERY_STRING} id=(\d+) [NC]
RewriteRule (.*) /category/view?id=%1 [L,R=301]
RewriteCond %{THE_REQUEST} index.php [NC]
RewriteCond %{QUERY_STRING} option=com_content [NC]
RewriteCond %{QUERY_STRING} view=article [NC]
RewriteCond %{QUERY_STRING} id=(\d+) [NC]
RewriteRule (.*) /article/view?id=%1 [L,R=301]
$url = Url::to(['post/view', 'id' => 100]);
create/index.php?r=post%2Fview&id=100
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question