How to remove /public/ from a Laravel URL

How to remove /public/ from a Laravel URL

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

How to remove /public/ from a Laravel URL

By default, modern web server configurations point your document root to the public directory within your project folder. While this is a robust security feature that isolates your application's core files, it often results in URLs prefixed with /public/. For developers juggling multiple projects on a single machine—such as when using MAMP or similar local stacks—this prefix adds unnecessary cognitive load and friction when switching contexts.

The immediate instinct is to modify the .htaccess file or adjust server permissions to rewrite requests so that http://localhost/project serves the content currently residing in http://localhost/project/public. However, as noted in many troubleshooting scenarios, a simple rewrite rule like:

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

often fails immediately. This specific configuration attempts to strip the requested path and serve content from a subdirectory relative to the current document root, which effectively breaks Laravel's routing mechanism. When you hit a route expecting a specific segment but receive a rewrite instead, Laravel throws a NotFoundHttpException (commonly seen at compiled line 7610 in older versions or equivalent locations in newer builds) because the controller cannot resolve the intended request.

The root cause is architectural: Laravel 5 and later versions strictly enforce the separation of concerns by requiring all HTTP traffic to enter through the public/index.php entry point. Moving this file out of the document root violates that contract, regardless of how cleverly you configure your web server.

The Document Root Solution

The cleanest solution that maintains Laravel's security boundaries while removing the URL prefix is to update your web server configuration to use the project directory as the document root instead of the public subdirectory.

In an MAMP environment, this involves editing the httpd.conf or the specific virtual host file associated with your project. You need to locate the directive defining the document root and point it directly to the parent folder containing artisan, app, and public.

For example, if your project is located at /Applications/MAMP/htdocs/my-project, you would configure the server to serve this directory directly. The web server will then handle requests for http://localhost/my-project by looking for files relative to that root. Since Laravel's entry point (public/index.php) resides in the public folder, the URL structure naturally becomes /my-project, effectively removing the redundant /public/ segment from your browser bar without altering any application code or .htaccess rules.

Implementation Steps

  1. Locate Configuration: Open the Apache configuration file for MAMP (typically found in /Applications/MAMP/conf/httpd.conf or within the htdocs directory as a specific <VirtualHost> block).

  2. Identify the Directive: Find the line starting with DocumentRoot. It might currently look like:

    DocumentRoot "/Applications/MAMP/htdocs/my-project/public"
    
  3. Update the Path: Change this to point to the project root:

    DocumentRoot "/Applications/MAMP/htdocs/my-project"
    
  4. Adjust Directory Permissions: Because you are now serving a directory that contains non-public files (like app, config, and vendor), you must ensure these folders remain inaccessible to the web server. You can do this by adding a <Directory> block immediately following the DocumentRoot line:

    <Directory "/Applications/MAMP/htdocs/my-project">
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
    <Directory "/Applications/MAMP/htdocs/my-project/public">
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    Note: Ensure that the app, config, and vendor directories do not have public access in your .htaccess or server config to prevent directory listing or file exposure.

  5. Reload Server: Restart MAMP or reload Apache to apply changes.

Trade-offs and Considerations

This approach requires a single configuration change per project if you manage multiple sites. Some developers prefer a global setting, but that is risky when mixing Laravel versions or projects with different security requirements. By configuring the document root individually per project folder, you retain flexibility.

It is crucial to understand that this does not mean your application files are now world-readable. The web server serves the public directory content only; requests for /my-project/app/Kernel.php will result in a 403 Forbidden error if proper <Directory> restrictions are applied. This preserves the security model of Laravel 5 while satisfying the convenience of a clean URL structure.

If you encounter issues where the application fails to boot after changing the document root, verify that APP_ENV is correctly set and that the framework bootstrap files can locate their assets relative to the new root. In rare cases involving symbolic links or complex directory structures, ensuring the physical path in the configuration matches the actual filesystem path is essential.

Our network