1

I referred the below given link

Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY

Remove index.php from url after removing web folder from frontend and backend in yii2

but, i did't get the output

show below URL

localhost/yii2advance/backend/web/index.php?r=site%2Flogin

localhost/yii2advance/frontend/web/index.php?r=site%2Flogin

in above url i remove /web/index.php in both frontend and backend

I get URL like

localhost/yii2advance/backend/site/login

localhost/yii2advance/frontend/site/login

2
  • Refer: yiiframework.com/wiki/755/… Commented Feb 25, 2016 at 11:10
  • your refer link remove frontend/web. i remove the /web/index.php in both frontend and backend Commented Feb 25, 2016 at 11:15

2 Answers 2

7

1- put this code in .htaccess flie in yii2advance folder (main folder of project)

# prevent directory listings
Options -Indexes
IndexIgnore */*

# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1

above code convert

'localhost/yii2advance/frontend/web/index.php'

to

'localhost/yii2advance/'

and it convert

'localhost/yii2advance/backend/web/index.php'

to

'localhost/yii2advance/admin'

2- add this code to frontend/web/.htaccess and backend/web/.htaccess file:

RewriteEngine on

# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

3- in backend/config/main.php put this codes:

'homeUrl' => '/yii2advance/admin',
'components' => [
'request' => [
        'baseUrl' => '/yii2advance/admin', // localhost/yii2advance/admin
    ],
    'urlManager' => [
         'enablePrettyUrl' => true,
         'showScriptName' => false,
         'rules' => [],
    ],

4- in frontend/config/main.php put this codes:

'homeUrl' => '/yii2advance',
'components' => [
'request' => [
    'baseUrl' => '/yii2advance', // localhost/yii2advance
 ],
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [],
],
Sign up to request clarification or add additional context in comments.

1 Comment

Hay! man, that cool everything working fine. the only change is 'request' => [ 'baseUrl' => '/yii2advance', // localhost/yii2advance ], it should come inside the components
-1

Create a ".htaccess" file in the "web" directory with:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

My pull request was accepted about this. It will be in the 2.0.19 version.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.