-2

I want to remove index.php from url. I put .htaccess in the root and wrote the following lines in common/config/main-local.php.
But every url is redirected to backend.

My .htaccess file:

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

My common/config/main-local.php file:

'urlManager' => [
  'class' => 'yii\web\UrlManager',
  // Disable index.php
  'showScriptName' => false,
  // Disable r= routes
  'enablePrettyUrl' => true,
  'rules' => array(
    '<controller:\w+>/<id:\d+>' => '<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
   ),
],

Note: I want to remove index.php from both frontend and backend.

1

1 Answer 1

-1

In .htaccess file(put .htaccess in frontend/web and backend/web )

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

And in frontend/config/main.php and backend/config/main.php:

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

4 Comments

But I have removed web folder.. where can I put these .htacess.
my frontend controller is working fine for view page.. But backend controller cannot find the view page.. always calling backend index page
Put it in root directory of project and edit backend and frontend config like the above code
Not working .. now every link in the menu is redirecting to sitename/backend/site/index..

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.