单域上的 yii2-app-advanced 对我不起作用

yii2-app-advanced on single domain not work for me

我根据 yii official wiki 配置了我的 yii2 advanced,以便在本地主机上的单个域中使用后端和前端。 我使用困难的方式修改文件

frontend/config/main.php

backend/config/main.php

并添加

.htaccess with mod_rewrite

根据维基。 当我去 http://localhost/ all things right.but when i go to http://localhost/site/about 和其他 link 时,浏览器显示

Object not found!

当我想去 http://localhost/backend/ browser redirect me to http://localhost/backend/site/login 并展示

Object not found!

再次。 我将这个 wiki 用于过去的 yii2 项目,没有任何问题。但现在我不能用了。 我怎么了? 我是伊朗人,我的英语不是很好。语言不通请见谅

我的问题已经解决了。 根据 this answerbackend/webfrontend/web 添加了额外的 .htaccess 文件,内容如下:

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

我在遵循 yii2 硬方式模板时遇到了同样的问题,然后我在配置、vhost 和 .htaccess 文件中进行了以下更改。

/frontend/config/main.php

return  [
        'homeUrl' => '/',
        'components' => [
            'request' => [
                'baseUrl' => '',
            ],
            'urlManager' => [
                'enablePrettyUrl' => true,
                'showScriptName' => false,
            ],
        ],
    ];

/backend/config/main.php

return  [
        'homeUrl' => '/admin',
        'components' => [
            'request' => [
                'baseUrl' => '/admin',
            ],
            'urlManager' => [
                'enablePrettyUrl' => true,
                'showScriptName' => false,
            ],
        ],
    ];

.htaccess 您需要在应用程序根目录中的 .htaccess 文件中添加下面提到的代码。如果您没有,则需要在高级应用程序的根目录中创建 .htaccess 文件。

Options FollowSymLinks
AddDefaultCharset utf-8

<ifmodule mod_rewrite.c>
RewriteEngine On

# the main rewrite rule for the frontend application
RewriteCond %{REQUEST_URI} !^/(backend/web|admin)
RewriteRule !^frontend/web /frontend/web%{REQUEST_URI} [L]

# redirect to the page without a trailing slash 
#RewriteCond %{REQUEST_URI} ^/admin/$
#RewriteRule ^(admin)/ / [L,R=301]
# the main rewrite rule for the backend application
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(.*) /backend/web/ [L]

# if a directory or a file of the frontend application exists, 
# use the request directly
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . /frontend/web/index.php [L]

# if a directory or a file of the backend application exists, 
# use the request directly
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . /backend/web/index.php [L]

RewriteCond %{REQUEST_URI} \.(htaccess|htpasswd|svn|git)
RewriteRule \.(htaccess|htpasswd|svn|git) - [F]
</ifmodule>

虚拟主机文件

<VirtualHost *:80>
DocumentRoot "path of your project" //no need to mention backend/frontend
ServerName "example.com"
<Directory "path of your project">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>