Question: Bellow is my site directory structure: 

```
htdocs/
    My-Project/
        public/
            index.php
            css/
            img/
            js/
        src/
            config.php
            templates/
            library/

```

I do not want any direct user access to any files inside the `src` directory. `src` contains my templating and backend logic scripts.

I want to set up my `.htaccess` so that when the user goes to my website (root folder `My-Project`), they are redirected to `My-Project/public/index.php`. I would like the URL to simply look like `My-Project.com` while on the index page.

Any help? I am hesitant to modify my .htaccess file as I see a lot of conflicting advice around here and on the net as to the best way to do this.

Answer: 
Place this code in `/My-Project/.htaccess`:

```
RewriteEngine On
RewriteBase /My-Project/

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

```
I made some changes to @anubhava's response to working on localhost and with friendly URLs.

**Directory structure:**

* / (localhost root folder)
	+ myapp/
		- public/
		- index.php
	+ core/
		- some core files ...

**myapp/.htaccess** (myapp root folder)

```
RewriteEngine On
RewriteBase /myapp

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

```

**myapp/public/.htaccess**

```
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

```

**myapp/public/index.php**

```
<?php
echo 'Hello<br>';
echo $_SERVER['QUERY_STRING'];

```

**Some requests:**

<http://localhost/myapp/>

> 
> Hello
> 
> 
> 

---

<http://localhost/myapp/post/new>

> 
> Hello 
> 
> 
> post/new
> 
> 
>