Yii2 provide default url with frontend/web and backend/web. In real web application these type of URL is not well, So in this case we need to remove frontend/web from the URL. Below example is best to remove the frontend/web from the URL.
First of all you need to set enablePrettyUrl true and showScriptName false.
In second step you just replace frontend/web with blank space.
In third step you need to create a .htaccess file inside the web folder.
frontend/config/main.php
use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl()); // you set override the frontend/web with blank space and it will return the baseUrl.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
]
'request' => [
'baseUrl' => $baseUrl,
]
frontend/web/.htaccess
Options -Indexes
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} admin
RewriteRule .* backend/web/index.php [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !admin
RewriteRule .* frontend/web/index.php [L]
</IfModule>
Nice Blog , This is what I exactly Looking for , Keep sharing more blog .
ReplyDeleteOutsource Yii Application Development in India