Yii2 Custom URL Management. Getting Error 400

Well, PHP time.

My client wants me to use Yii2 as the framework for my project.

I have earned. No problems. I used an advanced template using composer.

Install my web root in / frontend / web etc.

NOW, I want to use this URL format

website.com/messages/or website.com/messages/tom ... etc.

Currently, the setup path is shown by website.com/index.php?r=messages/index ...

I found this documentation ...

https://github.com/yiisoft/yii2/blob/master/docs/guide/url.md

But I can’t understand how it turns out.

Here are my steps ...

I configured the Apache server to specify / usr / www / payroll / frontend / web /

I added a .htaccess file with this content to my web folder.

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

urlManager . , .

'components'=>[
    'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => 'false'
        ],
],

, website.com, , /site/index url. ( url /index.php?site/index)

, , url ( UrlManager), 404

. Php, Apache Yii2. , .

+4
5

, .

recents Apache ( 2.3.9) AllowOverride NONE. AllowOverride ALL.

Yii2 , AllowOverride ALL.

Yii,

http://www.yiiframework.com/forum/index.php/topic/53295-url-manager-for-seo-friendly-url-404-error-code/

!

0

URL-, Yii 2.0, 2 :

1: /frontend/config/main.php ( ) :

'components'=>[
        'urlManager' => [
                'class' => 'yii\web\UrlManager',
                'enablePrettyUrl' => true,
                'showScriptName' => false,
            ],
    ],

2: .htaccess WEB ROOT.   yii 2.0 , :  /frontend/web

.htaccess example:

RewriteEngine on

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

RewriteRule . index.php
+15

'showScriptName' = > 'false' 'showScriptName' = > false,

+5

http://domain.com/controller_name/action_name, URL- :

'components'=>[
    'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => 'false'
        ],
],

URL- `website.com/messages/ website.com/messages/tom.

URL-, Yii 2 website.com/message?id=12

0

Yii2 basic /myappfolder/config/web.php:

'urlManager' = > [

'class' = > 'yii\web\UrlManager',

'enablePrettyUrl' = > true,

'showScriptName' = > ,

]

.htaccess /myappfolder/web/:

RewriteEngine on

RewriteCond% {REQUEST_FILENAME}! -f

RewriteCond% {REQUEST_FILENAME}! -d

RewriteRule. index.php

. , , .:)

0

Source: https://habr.com/ru/post/1535971/


All Articles