Yii2 + AngularJS

Ant*_*mov 12 .htaccess angularjs yii2

我有一个集成Angular和Yii2的问题我有2个部分:

  1. 常规的Yii2应用程序
  2. 控制器以actionIndex开头并与Angular一起使用

问题是,当我在Angular部分复制并粘贴url时,我总是得到404错误.Angular配置是

.config(function($routeProvider, $locationProvider) {
    base = '/construct/';
    $routeProvider.when(base+':className', {
      templateUrl: '/construct/builder',
      controller: 'BuilderCtrl',
      reloadOnSearch: false
    }).otherwise({
      templateUrl: '/construct/heroes',
      controller: 'HeroesCtrl'
    });

    $locationProvider.html5Mode(true);
  });
Run Code Online (Sandbox Code Playgroud)

那么,我如何在HTML5模式下进行直接链接才能看到正确的页面?像"/ construct/something"这样的路径不起作用.我的htaccess是:

RewriteEngine on

# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)

Bra*_*les 0

因为您正在使用虚拟目录(例如 Alias /site/“/dir/”),所以必须使用

RewriteBase /site/ 在你的 apache 配置文件中。