Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 如何从Yii2高级模板中删除/web/_Rest_Templates_Yii2 - Fatal编程技术网

Rest 如何从Yii2高级模板中删除/web/

Rest 如何从Yii2高级模板中删除/web/,rest,templates,yii2,Rest,Templates,Yii2,我正在使用Yii2高级模板实现RESTful服务。但是,我最终得到了REST服务的以下结构: http://localhost/MyProject/api/web/v1/user/1而它应该是 http://localhost/MyProject/api/v1/user/1 如何将/web/从URL路径中删除?如果要在自己的服务器上托管它,只需创建一个指向api/web的虚拟主机,就可以对其进行排序。 这是一个样本 服务器管理员webmaster@localhost ServerName ap

我正在使用Yii2高级模板实现RESTful服务。但是,我最终得到了REST服务的以下结构:

http://localhost/MyProject/api/web/v1/user/1
而它应该是
http://localhost/MyProject/api/v1/user/1


如何将
/web/
从URL路径中删除?

如果要在自己的服务器上托管它,只需创建一个指向
api/web
的虚拟主机,就可以对其进行排序。 这是一个样本


服务器管理员webmaster@localhost
ServerName api.websiteurl.com
DocumentRoot/var/www/html/app/api/web

这样,我就可以从
api.websiteurl.com

如果您想从
websiteurl.com
访问api,那么只需将服务器的文档根目录设置为指向
api/web

,我实际上喜欢使用Kartik的或。它们基于yii2高级模板,但是做了一些更改,比如在.htaccess中使用apache时去掉/web目录

You add below code in web.php file...

'components' => [
      'urlManager' => [
             'enablePrettyUrl' => true,
             'showScriptName' => false,
       ],
 ],


 And Then add one file .htaccess file in web folder..

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php
<IfModule mod_rewrite.c>
#Send all /api requests to api/web folder
RewriteRule ^api/(.*)$ api/web/$1
</IfModule>

#将所有/api请求发送到api/web文件夹
重写规则^api/(*)$api/web/$1

如果我不使用自己的服务器,而使用AWS或谷歌云平台,该怎么办?在我的本地机器上有没有这样的设置方法?没有
web.php
文件。我在配置目录web.php中有
web
目录,在
frontend
backend
中有三个配置目录。一个在
后端
,另一个在
前端
,第三个在
公共
中。这些文件中都没有web.php文件。