Yii2 убрать index php

Yii Framework

Здравствуйте. Проблема у меня.
Разработал приложение на Yii2. Работал на OpenServer. Все хорошо.

Перенес приложение на Debian 6 VDS.
Удалось запустить, возникла проблемка, никак не могу решить.

Не убирается в адресной строке index.php. То есть www.site.ru/index.php или просто www.site.ru — работает.
а если перейти
www.site.ru/site/index
то ошибка «адрес не найден».

Если дописываю index.php
www.site.ru/index.php/site/index
То работает. Странно все это. Можно конечно приспособится, но это не правильно и хотелось бы конечно, что бы нормальный адрес был.

root@vds238466:~# a2enmod rewrite Module rewrite already enabled 
RewriteEngine on # if a directory or a file exists, use it directly RewriteCond % !-f RewriteCond % !-d # otherwise forward it to index.php RewriteRule ./index.php 
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing'=>true, 'rules'=>[ [ 'pattern'=> '//', 'route'=> '/', 'suffix'=>'' ], [ 'pattern'=> '/', 'route'=> '/', 'suffix'=>'' ], [ 'pattern'=> '', 'route'=> '/index', 'suffix'=>'' ], [ 'pattern'=> '/', 'route'=> 'site/index', 'suffix'=>'' ], [ 'pattern'=> '', 'route'=> 'site/index', 'suffix'=>'' ] ] ], 
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing'=>true ], 

Источник

Читайте также:  Java decode class file

Yii2 убрать index php

Maybe it looks simple, but some time ago I need some time to find a solution of this case. I finally got it, and I want to share that I also experienced such cases. So that it can make reference.

Neither let us do the steps:

  • Make sure that the hosting / your pc mod_rewrite module is active. if not actively try to activate in a way, open the httpd.conf file. You can check this in the phpinfo.php to find out.

LoadModule rewrite_module modules/mod_rewrite.so ¶

LoadModule rewrite_module modules/mod_rewrite.so ~~~

RewriteEngine On RewriteBase / RewriteCond % !-f RewriteCond % !-d RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] 

if above does not work try with this: ~~~ RewriteEngine on

if a directory or a file exists, use it directly ¶

otherwise forward it to index.php ¶

 * move .htaccess file to root directory, where is index.php thare. 
  • protected
  • index.php
  • .htaccess

* Set main.php in your yii configuration, at component : 
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'caseSensitive'=>false, ), 

For reference material I managed to do in my personal website (check my profile).

NB: This for hide index.php

Revisions

more on mod_rewrite

From the site — «mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for http://www.somesite.com/widgets/blue/, but will really be given http://www.somesite.com/widgets.php?colour=blue by the server.»

Unclear purpose, example and .htaccess

Hi,
your article is a bit unclear about what is the goal you are trying to reach? Perhaps 1-2 examples would make things clearer:-) Also what is the final content of .htaccess file? (you may want to put it into solid code block pretty formatted).
Cheers
Lubos

hide index.php

showScriptName will not suffice?

Thanx for pretty formatting, now it’s clearer what you want to achieve.
Yet, the question is:
What is the benefit over setting the built-in paramater for urlManager in configuration:

thank you, you are right.
This can not be run if not in the main config settings.
~~~
Set main.php in your yii configuration, at component :
[php]
‘urlManager’=>array(

'urlFormat'=>'path', 'showScriptName'=>false, 

Not only check mod_rewrite instalation

To get mod_rewrite working not only modrewrite must be installed, but also check in the Apache directory config (/etc/apache2/sites-enabled/000-default_ on Ubuntu installed via apt-get) if the rule «AllowOverride None» exists in your project’s directory config. If so, change it to «AllowOverride All«. I have spent hours because of this thing, so it’s my tip to get things working.

RewriteBase PROJECTNAME

I am using WAMP, it works after i include the line:

win32 apache config

As thiromi said, make sure that you change the «AllowOverride» flag to «All»

# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # **AllowOverride All** 

Hello, May you take a look on my yii topic

Hello, May you take a look on my yii topic

yiiframework.com/forum/index.php/topic/33491-user-friendly-urls/pagep161195fromsearch1#entry161195

I have made what is required but it does not work.
I dont understand why.

That Sounds good

Thanks for this great article

I just tried it but I fail first because I forget and put this variables

'urlFormat'=>'path', 'showScriptName'=>false, 'caseSensitive'=>false, 

inside the array of the rules
🙂

I just a newbie with YII 🙂 so I’m just confused

One more thing.

Also, if you’re on a virtual directory (e.g. using

on your apache configuration) you MUST use a

statement on your .htaccess file, other than the rewrite won’t work again.

by «moving .htaccess to webroot» you mean delete .htaccess within protected folder? if so it’s horrible for security cause the protected folder is accessible for anyone.
i think you mean copy that .htaccess and use it for this urlManager and keep the other one.

Nice Article

Very Nice article ..thank you so much this works for me..

how to change the URL path?

how to change Url path like —

17695 Got it

i found the solution, simply add below script into urlManager array in main config file.

Please only use comments to help explain the above article.
If you have any questions, please ask in the forum instead.

Источник

Yii Framework

Я работаю на deploiment и при добавлении этой строки исчезает строка внизу экран, строка с статусом страницы и другими плюшками для разработки.
Пишет «The requested URL /debug/default/toolbar was not found on this server.»
«Apache/2.4.10 (Ubuntu) Server at auto.com Port 80»

Пути к страницам меняются и все возвращают 404.

 ServerAdmin duda.ml1986@gmail.com ServerName auto.com ServerAlias auto.com DocumentRoot /var/www/auto.com/public_html/frontend/web/ 
 # Включаем mod_rewrite RewriteEngine On # Если это папка или файл, открываем её/его RewriteCond % !-f RewriteCond % !-d # В противном случае перенаправляем на index.php #RewriteRule . index.php RewriteRule ^index.php$ / [QSA,R] 
return [ 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'urlManager' => [ // указали используемый класс 'class' => 'yii\web\UrlManager', // что хотим делать с классом, параметры // ЧПУ 'enablePrettyUrl' => true, //скрывать index.php //'showScriptName' => false, ], ], ]; 

krosh87 Сообщения: 160 Зарегистрирован: 2015.02.18, 15:32 Контактная информация:

Re: Как убрать index.php из адресной строки?

Сообщение krosh87 » 2015.08.23, 12:33

Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if request dosn't start with web add it RewriteCond % !^/(web) RewriteRule (.*) /web/$1 # if file or directory dosn't exists go to /web/index.php RewriteCond % !-f RewriteCond % !-d RewriteRule . /web/index.php
Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if request begins with /admin remove admin and ad /backend/web/ RewriteCond % ^/admin RewriteRule ^admin\/?(.*) /backend/web/$1 # other requests add /frontend/web/$1 RewriteCond % !^/(frontend/web|backend/web|admin) RewriteRule (.*) /frontend/web/$1 # if frontend request RewriteCond % ^/frontend/web RewriteCond % !-f RewriteCond % !-d RewriteRule . /frontend/web/index.php # if backend request RewriteCond % ^/backend/web RewriteCond % !-f RewriteCond % !-d RewriteRule . /backend/web/index.php

Следующий шаг это добавление Url менеджера в config\web.php, для расширенной версии фреймворка это common\config\main.php

'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ] ], 

Источник

Как убрать frontend/web/index.php c url в yii2 advanced?

Bandicoot

'components' => [ 'urlManager' => [ 'showScriptName' => false ] ]

Остальное настраивается через .htaccess, погуглите

Ещё в frontend/config/main.php добавить:

greenkaktusx

kentuck1213

arutyunov

kentuck1213

arutyunov

arutyunov

Войдите, чтобы написать ответ

Как в yii2 отправить фатальную ошибку?

С каким интервалом времени установить команды на cron?

Я залил сайт yii2 на хостинг beget, а н выдает ошибку, как это исправить?

Где именно происходит заполениние created_at в модели User в Yii2?

Ошибка при установке дополнений на yii2?

Как исправить наезд двух div Boostrap 4 Yii2?

Кастомные поля в GridView?

Вопрос по путям в yii2?

Динамическая связь в Yii2. Как сделать?

Минуточку внимания

  • Как проще найти большую и малую полуось эллипса ошибок?
    • 2 подписчика
    • 0 ответов
    • 3 подписчика
    • 2 ответа
    • 2 подписчика
    • 2 ответа
    • 2 подписчика
    • 2 ответа
    • 2 подписчика
    • 3 ответа
    • 2 подписчика
    • 1 ответ
    • 1 подписчик
    • 1 ответ
    • 2 подписчика
    • 3 ответа
    • 2 подписчика
    • 0 ответов
    • 2 подписчика
    • 0 ответов

    Источник

Оцените статью