# Not able to fix .htaccess for Mezzio

**URL:** <https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994>\
**Category:** Mezzio\
**Created:** [December 10, 2020, 5:12pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994 "2020-12-10T17:12:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blacktornado](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/blacktornado/32/815_2.png) [@Blacktornado](https://discourse.laminas.dev/u/Blacktornado)\
**Post date:** [December 10, 2020, 5:12pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/1 "2020-12-10T17:12:18Z")

</div>

Hello Everyone, I am currently trying to use `.htaccess` file for one of my `Mezzio` project, but unfortunately not working. However there is another project that runs on `Php Slim` framework and the `.htaccess` is working there. So I am assuming that the server has nothing to with this. I figured out to use `$basePath = $request->getAttribute(\Blast\BaseUrl\BaseUrlMiddleware::BASE_PATH);` for `RedirectResponse` from handler.

My current structure is

- htdocs
  - Mezzio
    - .htaccess
    - public
      - .htaccess

the `.htaccess` inside mezzio

```
RewriteEngine On
RewriteRule (.*) ./public/$1

```

`.htaccess’ inside public

```
RewriteEngine On
# The following rule allows authentication to work with fast-cgi
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

```

Any help will be highly appreciated

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 11, 2020, 10:26am UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/2 "2020-12-11T10:26:42Z")

</div>

> [@Blacktornado](#):
>
> So I am assuming that the server has nothing to with this. I figured out to use `$basePath = $request->getAttribute(\Blast\BaseUrl\BaseUrlMiddleware::BASE_PATH);` for `RedirectResponse` from handler.

Why are you using the `.htaccess` files?

My suggestion: Set up your server / hosting package so that your domain will ends in `public`. (Hence the name “public”). Then no extra middleware is needed.

---

<div class="post-metadata">

**Author:** ![Blacktornado](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/blacktornado/32/815_2.png) [@Blacktornado](https://discourse.laminas.dev/u/Blacktornado)\
**Post date:** [December 14, 2020, 12:16pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/3 "2020-12-14T12:16:27Z")

</div>

Thanks for the reply @froschdesign what i am trying to understand is my .htaccess file is being detected as writing some garbage inside .htaccess file is throwing 500 internal server error.  
so i have to tweak the httpd.conf file for this specific project named `mezzio` and point to the public folder is this what you are saying. can you please elaborate a little more into this  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 14, 2020, 1:02pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/4 "2020-12-14T13:02:58Z")

</div>

I’m sorry I mean why are you using two `.htaccess` files? Only the `.htaccess` file in the `public` folder is relevant.

---

<div class="post-metadata">

**Author:** ![Blacktornado](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/blacktornado/32/815_2.png) [@Blacktornado](https://discourse.laminas.dev/u/Blacktornado)\
**Post date:** [December 14, 2020, 1:16pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/5 "2020-12-14T13:16:15Z")

</div>

@froschdesign i removed the .htaccess file outside public folder now i am getting  
`Forbidden - by rule. You do not have permission to access /demo-app/ on this server.`

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 14, 2020, 1:22pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/6 "2020-12-14T13:22:53Z")

</div>

> [@Blacktornado](#):
>
> Forbidden - by rule. You do not have permission to access /demo-app/ on this server.

Update the `DocumentRoot` of your virtual host for this application and use the `public` folder as target.

---

<div class="post-metadata">

**Author:** ![Blacktornado](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/blacktornado/32/815_2.png) [@Blacktornado](https://discourse.laminas.dev/u/Blacktornado)\
**Post date:** [December 14, 2020, 6:38pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/7 "2020-12-14T18:38:47Z")

</div>

@froschdesign i am still not convinced by the fact that i need to edit the config files that is already working for all other projects to get this working.  
All i want is to omit the public/index.php from my url’s . i looked into this [https://docs.mezzio.dev/mezzio/v3/cookbook/using-a-base-path/](https://docs.mezzio.dev/mezzio/v3/cookbook/using-a-base-path/) but i am not running it from subdirectory .

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 14, 2020, 6:49pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/8 "2020-12-14T18:49:44Z")

</div>

I’m sorry, but I don’t know your setup, your directory structure or any of your other applications.  
`/demo-app/` is not included in your first post and I don’t know where it comes from. And if I understand your first post correctly then your are running the Mezzio from a subdirectory, it’s `public`.

Please keep in mind: No one here is a magician or wizard and we can not see your desktop. 😉

---

<div class="post-metadata">

**Author:** ![Blacktornado](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/blacktornado/32/815_2.png) [@Blacktornado](https://discourse.laminas.dev/u/Blacktornado)\
**Post date:** [December 14, 2020, 7:13pm UTC](https://discourse.laminas.dev/t/not-able-to-fix-htaccess-for-mezzio/1994/9 "2020-12-14T19:13:52Z")

</div>

i am sorry i started with mezzio as the application name and then named it `demo-app` . it resides inside htdocs only. the directory structure is the same as the first post and htdocs is the root so i am hoping that its not from subdirectory.  
@froschdesign thanks a lot for the quick reply
