# Deploying Slim to an existing website

**URL:** <https://discourse.slimframework.com/t/deploying-slim-to-an-existing-website/4045>\
**Category:** Questions\
**Created:** [April 11, 2020, 11:59am UTC](https://discourse.slimframework.com/t/deploying-slim-to-an-existing-website/4045 "2020-04-11T11:59:28Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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:** [April 11, 2020, 1:59pm UTC](https://discourse.slimframework.com/t/deploying-slim-to-an-existing-website/4045/7 "2020-04-11T13:59:02Z")

</div>

Ok I know whats the problem. The current directory structure will not work in real life.

In a web application / website, it is important to distinguish between the public and non-public areas.

The `public/` directory serves your application and will therefore also be directly accessible by all browsers, search engines and API clients. All other folders are not public and must not be accessible online. This can be done by defining the `public` folder in Apache as `DocumentRoot` of your app / website.

I have written about this this topic in this [Slim 4 Turorial](https://odan.github.io/2019/11/05/slim4-tutorial.html).

The “solution” is quite simple:

1. Move the file `index.php` file into `public/` directory (maybe fix some paths to the autoloader)
2. Move your public “assets” (js, css etc) directory into the `public/` directory too
3. In your prod env: Define the public/ path as your `DocumentRoot`
4. Create a file: `public/.htaccess` with this content:

```auto
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

1. Create a second `.htaccess` file above the `public/` directory with this content:

```auto
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

```

The second `.htaccess` file is only importand for your local development environment, but can be deployed too.

---

_[View the full topic](https://discourse.slimframework.com/t/deploying-slim-to-an-existing-website/4045)._
