# Newbie, How to access Slim framework by URL

**URL:** <https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731>\
**Category:** Questions\
**Created:** [March 29, 2021, 9:41am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731 "2021-03-29T09:41:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 29, 2021, 9:41am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/1 "2021-03-29T09:41:47Z")

</div>

According to I install slim on [http://localhost/Learn/SlimAPI/API/](http://localhost/Learn/SlimAPI/API/)  
I can open slim by localhost:8080 on brownser but when I tried to open it base on location like  
[http://localhost/Learn/SlimAPI/API/public/](http://localhost/Learn/SlimAPI/API/public/)  
why it’s error  
any way I can open it?

 ![slim](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/b/bd127fba004ece219dd7cad8dac42497130197bc.png)

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 29, 2021, 11:04am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/2 "2021-03-29T11:04:46Z")

</div>

Please note, the `public/` directory must not be part of the url.  
Have you already set up CORS? [Setting up CORS](https://www.slimframework.com/docs/v4/cookbook/enable-cors.html)

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 30, 2021, 2:32am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/3 "2021-03-30T02:32:04Z")

</div>

I add the CORS on app/routes.php as below but response from server is the same

 ![response](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/a/aca3e0036bc10dde83ecc912ed97ed2d20874053.png) ![route](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/4/4110040bcbe98c414065928ec8c8f347fd98acf7.png)

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 30, 2021, 3:18am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/4 "2021-03-30T03:18:03Z")

</div>

I add the command on index.php and it is work as below

 ![CORS](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/c/cd9dff888e12a27a467459e79b792adf99c274bb.png)

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 30, 2021, 3:40am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/5 "2021-03-30T03:40:04Z")

</div>

What Should I do when I want to upload my slim PHP to a website and would like to use real URL like

`http://www.aaa.com/developer/customer/list`

like this

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 30, 2021, 8:22am UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/6 "2021-03-30T08:22:39Z")

</div>

I wrote an article about this topic. Maybe you will find an answer there. [Slim 4 - CORS](https://odan.github.io/2019/11/24/slim4-cors.html).

You have to check for the allowed hosts. When it’s valid you just send an `*` instead.

```php
$response = $response->withHeader('Access-Control-Allow-Origin', '*')

```

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 31, 2021, 1:35pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/7 "2021-03-31T13:35:13Z")

</div>

Yes, Now it’s work.  
so How can I upload my project to real host on internet and I don’t want to run command like this

php -S localhost:8081 -t public public/index.php

How can I get URL like [http://example.com/customer/add](http://example.com/customer/add) ?

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 31, 2021, 2:51pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/8 "2021-03-31T14:51:09Z")

</div>

You need a [webhosting](https://en.wikipedia.org/wiki/Web_hosting_service) and a [domain](https://en.wikipedia.org/wiki/Domain_name). You can find it in [google](https://www.google.com/search?q=webhosting).

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 31, 2021, 2:54pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/9 "2021-03-31T14:54:02Z")

</div>

I know that I mean after I upload slim folder to my wen hosting. what’s the URL of API exmaple I upload slim to htdoc/slim/

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 31, 2021, 2:59pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/10 "2021-03-31T14:59:32Z")

</div>

You should upload your local project directly into the `htdocs/` directory of the webserver. When you upload it into a sub-directory of `htdocs/`, then your URL contains the path of that sub-directory. But again, to get a URL as mentioned above, just upload the source directly into the `htdocs/` directory and not into `htdocs/slim/`.

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 31, 2021, 3:03pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/11 "2021-03-31T15:03:54Z")

</div>

so for slim I can’t upload to `htdocs/slim/` ? why ? will it not work?

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 31, 2021, 3:08pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/12 "2021-03-31T15:08:59Z")

</div>

Of course you can, it’s your server 🙂

Your question was how to get a url like `http://example.com/customer/add`, and this was my answer to this specific question. When you upload it into `htdocs/slim/` then you may have another URL, like `http://example.com/slim/customer/add`. Is this what you want?

---

<div class="post-metadata">

**Author:** ![lung](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@lung](https://discourse.slimframework.com/u/lung)\
**Post date:** [March 31, 2021, 3:23pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/13 "2021-03-31T15:23:18Z")

</div>

When I upload it into `htdocs/slim/` then my URL is not [http://example.com/slim/public/index.php](http://example.com/slim/public/index.php)?  
so I not need to go to Slim’s public directory, right?

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [March 31, 2021, 4:38pm UTC](https://discourse.slimframework.com/t/newbie-how-to-access-slim-framework-by-url/4731/14 "2021-03-31T16:38:08Z")

</div>

The `public/` directory should be the [DocumentRoot](https://httpd.apache.org/docs/2.4/en/mod/core.html#documentroot) directory of your webserver and must never be part of the URL. Also `index.php` must never be in the URL. `public/index.php` is the “front controller” and is the entry point to your Slim application. Is this an Apache webserver? Do you have set up the `.htaccess` files? This [Slim tutorial](https://odan.github.io/2019/11/05/slim4-tutorial.html) explains everything in detail how to configure Slim for Apache. The easiest way for you would be to configure the DocumentRoot to `htdocs/public/` or `htdocs/slim/public/`. You may ask your webhosting provider how to change this setting.
