Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can remove /web from URL? #7

Open
faravaghi opened this issue Dec 17, 2015 · 8 comments
Open

How can remove /web from URL? #7

faravaghi opened this issue Dec 17, 2015 · 8 comments

Comments

@faravaghi
Copy link

Hi @deerawan,
how can remove /web from url?

for example localhost/api/web/v1/countries become localhost/api/v1/countries.
or remove /web/v1?

please Describe how to change the form http://api.example.com/countries

@deerawan
Copy link
Owner

Hi @faravaghi

It is better if you use virtual host so you can decide what URL you want to use. More info https://httpd.apache.org/docs/2.2/vhosts/examples.html

@faravaghi
Copy link
Author

thx friend,
and remove /web/v1 with htaccess rule?

@deerawan
Copy link
Owner

@faravaghi yes, it can :)

@faravaghi
Copy link
Author

well, how?

@mvofreire
Copy link

@faravaghi You found any solution?

@faravaghi
Copy link
Author

Hi mvofreire,
No can not, but in another way I solved
in cpanel create a subdomain and link to /public_html/api/web and now i can access this link http://api.example.com/v1/countries

@mvofreire
Copy link

@faravaghi i found a simple solution, but i dont know is better one!

i created a file "index.php" at /api - (root) with the following code

<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../common/config/main.php'),
    require(__DIR__ . '/../common/config/main-local.php'),
    require(__DIR__ . '/config/main.php')
);

$application = new yii\web\Application($config);
$application->run();

And i Created .htaccess file in the same directory

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

I tested in postMan "http://localhost/serverRest/api/v1/countries" and got this response

[{"code":"AU","name":"Australia","population":18886000},{"code":"BR","name":"Brazil","population":170115000},{"code":"CA","name":"Canada","population":1147000},{"code":"CN","name":"China","population":1277558000},{"code":"DE","name":"Germany","population":82164700},{"code":"FR","name":"France","population":59225700},{"code":"GB","name":"United Kingdom","population":59623400},{"code":"IN","name":"India","population":1013662000},{"code":"RU","name":"Russia","population":146934000},{"code":"US","name":"United States","population":278357000}]

-- Sorry for my English

@futuralis
Copy link

ISSUE1: Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist:
..../yii2-api/vendor/bower/jquery/dist

I see a vendor/bower-asset directory, but not a vendor/bower directory....

Please help.

SOLVED: by renaming vendor/bower-asset directory to vendor/bower

ISSUE2: yii\web\Request::cookieValidationKey must be configured with a secret key.

SOLVED: under common/config/main-local.php
add

return [ 'components' => [ .................... 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'uRqj3HcbYA5MFxF3', ], ], ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants