В Yii2 есть такой компонент, который позволяет работать без указания index.php файла:
1 2 3 4 5 6 |
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], |
Для работы этого компонента также нужно произвести настройку ngnix или apache, смотря что у вас стоит
Для nginx в файл конфигураций необходимо добавить след код:
1 2 3 4 |
location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } |
Будьте внимательны, если у вас уже есть такой блок location, вам нужно просто скопировать строчку:
1 |
try_files $uri $uri/ /index.php$is_args$args; |
Для apache нужно добавить в месте где у вас файл index.php файл .htaccess и в него написать:
1 2 3 4 5 6 7 8 9 10 |
Options +FollowSymLinks IndexIgnore */* 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 |
Вы так же можете прописать эти настройки в файле конфигураций apache — httpd.conf:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DocumentRoot "path/to/web" <Directory "path/to/web"> # use mod_rewrite for pretty URL support 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 # ...other settings... </Directory> |
Не забудьте поменять path/to/web на путь до корневой папки где у вас лежит файл index.php