Showing posts with label remove web index php in yii2. Show all posts
Showing posts with label remove web index php in yii2. Show all posts

Friday, March 30, 2018

How to hide frontend/web and backend/web in Yii2

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>

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search