Rest 如何从Yii2高级模板中删除/web/
我正在使用Yii2高级模板实现RESTful服务。但是,我最终得到了REST服务的以下结构: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
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文件。