尝试在Yii2和cleanUrls中配置API模块时发生Apache错误

时间:2019-01-25 17:27:26

标签: .htaccess yii2

我正在尝试将API添加到基本的yii2模板,但是无法正常工作。我的目录结构如下:

$ tree -L 3
.
├── api
│   ├── config
│   │   ├── api.php
│   │   └── params.php
│   ├── modules
│   │   └── v1
│   └── web
│       └── index.php
│       └── .htaccess
├── config
│   ├── console.php
│   ├── params.php
│   └── web.php
├── controllers
├── models
├── views
├── web
│   ├── assets
│   ├── css
│   ├── index.php
│   └── .htaccess
├── widgets
│   └── Alert.php
├── yii
├── composer.json
├── composer.lock
└── .htaccess

我创建了以下.htaccess个文件,在根目录中一个,在每个web目录中一个

.htaccess

Options -Indexes

RewriteEngine on
#if the request is not to the backend, route it to /frontend/web
RewriteCond %{REQUEST_URI} !^/api
RewriteRule ^(.*)$ /web/$1 [L]

#otherwise route the request to the backend
RewriteRule ^api/(.*)$ api/web/$1 [L]

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

api / web / .htaccess

Options +SymLinksIfOwnerMatch

# otherwise forward it to index.php
IndexIgnore */*

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

api模块的baseUrl设置为

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

仍然,我收到以下错误消息:

[Fri Jan 25 18:24:59 2019] [error] [pid 3540] core.c(3870): [client 79.208.0.0] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace

当尝试调用/api以下的任何内容时,也尝试从主应用程序调用任何其他站点,如controller/action时,都会收到此错误消息。

我还尝试了以下.htaccess文件

Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/api/$
RewriteRule ^(api)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/api
RewriteRule ^api(.+)$ /api/web/$1 [L,PT]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /web/$1

0 个答案:

没有答案