yii2 .htaccess子目录路由不起作用

时间:2017-08-20 14:26:13

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

根目录中的htaccess配置类似于

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(assets|css|js|images|blog)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
RewriteRule ^blog/(.*)$ frontend/web/blog/$1 [L]
RewriteRule ^(.*)$ frontend/web/$1 [L]

RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|blog)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php

前端/网页中的

看起来像

RewriteEngine on
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc

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

RewriteRule . index.php

一切正常,图像,css,js(例如,路径site.com/images正常工作)除了“/ blog”页面,点击菜单按钮后,app将我重定向到“site.com/frontend/web / blog“而不是”site.com/blog“
即时通讯使用yii2 NavBar小部件

$menuItems = [
  ...
       ['label' => 'Blog', 'url' => ['/blog/index'], 'options'=>['class'=>'font-menu']],

网址管理员规则

        'rules' => [
            'blog/<url>/<category_id>' => 'blog/one',
            'blog/<category_id>' => 'blog/category',
            'blog' => 'blog/index',

不明白如何解决,请帮助

1 个答案:

答案 0 :(得分:0)

以这种方式找到解决方案

在main-local config

    'request' => [
        'baseUrl' => '',
    ],