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

时间:2017-03-27 04:54:55

标签: php .htaccess mod-rewrite yii2 yii2-advanced-app

我根据yii official wiki配置了yii2高级版,以便在localhost上的单个域中使用后端和前端。 我用硬方式修改文件

frontend/config/main.php

backend/config/main.php

并添加了

.htaccess with mod_rewrite

根据维基。 当我去http://localhost/所有事情的时候。但是当我转到http://localhost/site/about和其他链接时,显示的是浏览器

Object not found!

当我想转到http://localhost/backend/时,浏览器会将我重定向到http://localhost/backend/site/login并显示

Object not found!

一次。 我使用这个wiki过去的yii2项目没有任何问题。但现在我无法使用。 我错了什么? 我是伊朗人,我的英语不太好。原谅我的语言不好。

2 个答案:

答案 0 :(得分:1)

我的问题已经解决了。 根据{{​​3}}将.htaccess个额外backend/web个文件添加到frontend/webRewriteEngine 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 的内容:

MemoryPolicy

答案 1 :(得分:1)

当我遵循yii2硬路模板时,我遇到了同样的问题,然后我在config,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)/ /$1 [L,R=301]
# the main rewrite rule for the backend application
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(.*) /backend/web/$1 [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>

vhost文件

<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>