Answer the question
In order to leave comments, you need to log in
How to make a redirect without changing the url?
The bottom line is this:
there is a url with GET. http://test.ru/?s%5bcategory%5d=8
it is necessary for the server to receive it with such a request: test.ru/komnata
what rule to write in htaccess?
Those. so that the server receives get but does not display it in the url
No regulars are needed, I have only a few static pages with such key-values
For now, so far:
RewriteCond %{REQUEST_URI} /studiya/
RewriteRule ^(.*)$ /?s\[category\]=4\&s\[kinds\]\[\]=7 [R=301,L]
Answer the question
In order to leave comments, you need to log in
Knowing your version, I explain that there are roles in the urlManager that must be specified. If get requests are used in the roles, then you need to take into account whether it is a number or a string, if it is a number, set the value to 'd' (digital) if it is a string, specify the value 'w' (word), as in the example:
'urlManager'=> [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules'=> [
// возвратит название домена, без слэша ( 1 )
'' => 'site/index',
// возвратит экшен без названия папки контроллера ( 2 )
'<action:(login|logout|new|index|contact)>' => 'site/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
// возвратит get запрос с ссылкой, у которой переменная $link отобразит строку ( 3 )
'site/news/<link:\w+>' => 'site/news',
],
],
public function actionNews($link = '') {
// делаем get запрос
$get = News::find()->where(['link' => $link])->one();
return $this->render('news', ['link' => $link, 'get' => $get,]);
}
// это для примера, писать не надо
<?php
$link = 'first';
?>
http://mysite.host/frontend/web/site/news/first
/frontend/web/
, you will have to change session and request , this can lead to the loss of directories for many styles and scripts, and will block the oxygen of the backend section, but you can make a module, create your own layout and separate this section in the frontend so that it is like a backend, at the same time, the folders with the admin panel will be in the frontend, the operation is complex and requires knowledge of the Yii2 architecture, I draw knowledge from the documentation , although it is in English, but there are familiar Yii2 code fragments and even examples are described and how and what to apply. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question