Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daniel.atienza's avatar

Help, how do I remove public/index.php in url, having NotFoundHttpException

Hello, Im a beginner at laravel. I've seen the discussions but nothing seem to work for me. Im using XAMPP, and adding .htaccess and renaming the server.php to index.php in root worked in removing the public/index.php BUT whenever I use the navigations that changes the route/url, laravel throws a NotFoundHttpException. Please help

0 likes
7 replies
ZaffJa's avatar

First of all you don't need to remove index.php on public folder. That's the only file access your server can read, the rest will be handled Laravel. So revert back all the changes you made. Have you added the url you want to navigate inside routes/web.php? Without some codes I can't really help that much.

1 like
daniel.atienza's avatar

Hello ZaffJa, sorry for my poor delivery. I did not remove any file inside public folder what I meant by that is I have removed the /public/index.php from the url but the routing is not working

what I did in the root is I renamed server.php to index.php and added .htaccess file that contains

<IfModule mod_rewrite.c>
  DirectorySlash Off
  RewriteEngine on
  RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

yes, my routes/web.php is working fine. I just want to remove the /public/index.php from url. Im currently using localhost/example/public/index.php but I want to use "locahost/example" only. is that possible?

daniel.atienza's avatar

I got it working but I have a follow up question @jlrdw Im having a NotFoundHttpException whenever I try to access the website outside the local network.

what I've done to make it work is

  1. created public_html folder inside the htdocs
  2. moved public contents to public_html
  3. change the path values of include in public_html/index.php

I dont understand what to edit in .env file so I ignored that.

I can access the site on the local network but unfortunately cant when I use it outside the network or online. How can I fix this?

Snapey's avatar

All your Laravel content should be in the folder above htdocs, and htdocs used instead of public (copy all of public into htdocs folder).

1 like
larafever's avatar

@daniel.atienza, What I normally do is divide my project into two folders

1.public_html 2.root

The public html containers all my assets ( JS, CSS, images etc ) and can be accessed using blade helper {{URL::to("public_html//")}}

The root contains all laravel base default files and folders expect the PUBLIC folder... This mean you can run artisan command here so you just open cmd in this folder then you set to go..

Now the PUBLIC folder needs to be eliminated and therefore all files in it has to be moved to the base folder so we get the PUBLIC_HTML, ROOT, and the moved files in the base folder ....

U can delete the public folder since it will be empty now..

Now it's time to direct your index.php file to ROOT folder where your app starts...

Change the AUTOLOAD.PHP path to / ROOT/BOOTSTRAP/AUTOLOAD. PHP

Do the same for APP.PHP

/ROOT/BOOTSTRAP/APP.PHP

Done... We are go to load our app without the public and without torching the .HTACCESS file

Now when hosting we can put our ROOT folder containing our app even away from the public_html folder on live server and drop it from visitors reach so no one can get directe access to the ROOT folder, we just tweak our INDEX.PHP file to point to it safely

1 like
vishnu_sadanandan's avatar

It is not a good method to create a public_html folder. Try to set the .htaccess file. Also check that your web server apache has enabled the rewrite mode to true

https://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2

Then add a .htaccess file to your root folder. Then point it to the public/ folder in root folder.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/ [L]
</IfModule>

Try to run the url on browser.

1 like

Please or to participate in this conversation.