S
S
Sergey Evstigneev2015-10-28 16:33:35
Yii
Sergey Evstigneev, 2015-10-28 16:33:35

How to get rid of index.php in Yii2 via urlManager? Why is the server throwing an error?

Everything would be fine, and partially I have already configured the URL through urlManager, but as soon as I add
'showScriptName' => false , the server returns a 500 error on internal pages.
What could be wrong?
Part of frontend/config/main.php code

<?php
    'components' => [
        //...
        'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
        ],
    ],
    ],
    'params' => $params,
];

.htaccess content
Options +FollowSymLinks

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

What is most interesting, the main page without index.php shows, and the internal one is ready to show only like this: index.php/site/about , although the links in the Navbar already lead to /site/about

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergi0Limit, 2015-10-28
@sergevstigneev

The best solution I've used works from here mickgeek.com/yii-2-advanced-template-on-the-same-d... , to be precise, from here https://github.com/mickgeek/yii2- advanced one home...

V
Vitaly Khomenko, 2015-10-28
@iiifx

.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ /index.php/$1 [L]

... config/main.php
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            // ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question