Basit
Basit

Reputation: 1840

How to remove /web/ from Yii2 Advanced Template

I'm implementing a RESTful service using Yii2 advanced template following this guide. However, I'm ended up getting the following structure for the REST service:

http://localhost/MyProject/api/web/v1/user/1 whereas it should be http://localhost/MyProject/api/v1/user/1.

How can I remove the /web/ from the URL path?

Upvotes: 1

Views: 430

Answers (4)

The Sammie
The Sammie

Reputation: 1248

If you are going to host it on your own server, just create a virtual host pointing to the api/web and you will have it sorted. Here is a sample

<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName api.websiteurl.com DocumentRoot /var/www/html/app/api/web </VirtualHost>

With that, I can access my api from api.websiteurl.com If you want to api to be accessed from websiteurl.com, then just set the document root of your server to point to api/web

Upvotes: 0

Tahiaji
Tahiaji

Reputation: 430

If you use apache in .htaccess

<IfModule mod_rewrite.c>
#Send all /api requests to api/web folder
RewriteRule ^api/(.*)$ api/web/$1
</IfModule>

Upvotes: 1

marche
marche

Reputation: 1756

I actually like to use Kartik's Practical App or Practical-A App. They are based on the yii2-advanced template, but with some changes, like getting rid of the /web directory

Upvotes: 0

vishuB
vishuB

Reputation: 4261

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

Upvotes: 0

Related Questions