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

dkarthik's avatar

Remove public/index.php from URL

Hi,

How to remove public/index.php from the URL. I am developing laravel project inside normal php project as sub folder.

Thanks in advance.

0 likes
19 replies
henninghorn's avatar

@dkarthik

You'll need to use some alias or rewrite to do that in your case, or at least it sounds like that. Or you could create a virtual host with the document root being public.

pmall's avatar

The root of your vhost must be the public folder.

bashy's avatar

For anything like this you will need to tell us what web server software you're using...

thanhmabo's avatar

Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. — Thats it !! :)

3 likes
Coderooney's avatar

@dkarthik If you still need any help getting this sorted, could you please tell us what kind of server you have? You will have installed or be running something like these: Apache, nginx, Homestead, Laragon, XAMPP, LAMP, WAMP, PHP built-in server.

shipu's avatar

You can add an .htaccess file in the root of your Laravel application, with this content:

<IfModule mod_rewrite.c>

  # Turn Off mod_dir Redirect For Existing Directories
  DirectorySlash Off
  
  # Rewrite For Public Folder
  RewriteEngine on
  RewriteRule ^(.*)$ public/$1 [L]

</IfModule>
5 likes
rogueninja's avatar

@shipu Awesome! I'm just starting up with Laravel and found your solution. Just curious if there are any drawbacks with this method?

cent040's avatar

Here is complete .htaccess file

 <IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
        Options -MultiViews
   </IfModule>

RewriteEngine On
RewriteBase /your-folder-name/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

codenex's avatar

There is already a .htaccess and web.config in the public directory. If you're serving your site correctly then it should just work.

Start by stating what web server you are using and someone can give you a more detailed response.

Ac1988's avatar

I had this issue today. I am running my dev server using Mamp Pro on windows 10 and sorted this by doing the following.

Rename the server.php in the your Laravel root folder to index.php.

Sorted.

Ac1988's avatar

@bashy of course this is only for a dev environment if you want to get stuff working. Do you know another way to get this to work on a dev server like Xampp?

Snapey's avatar

@Ac1988

@bash y of course this is only for a dev environment if you want to get stuff working. Do you know another way to get this to work on a dev server like Xampp?

Yes, just set the document root correctly in your apache element of Xampp so that it points to /public

1 like
jlrdw's avatar

@Snapey usually pointing one way in development and installing another way on a live server doesn't make sense. In xampp, laravel can be installed above htdocs to duplicate a live server install with the public stuff under htdocs. Technically xampp is no different from a live server.

If people would develop mirrored just like the production will be, they would get it right.

No offense to this poster, but comments like

Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder.

are leading people the wrong way.

I wish Jeffrey would do a video of an install on hostgator or godaddy just to demo a shared hosting install, where you ftp up your site.

I have a 5.1 on godaddy, works fine. And yes above public_html, which is like htdocs on godaddy.

In fact @snapey it's from a post you helped me with a long time ago is how it's installed.

1 like
insight's avatar

I am using Laravel 10. My current .htaccess file in /public folder is

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

I got apache error as


[Thu Nov 02 16:03:15.412009 2023] [core:error] [pid 206214:tid 206403] [client 10.64.241.20:55062] AH00124: Request exceeded the limit of 100 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Please advise

Please or to participate in this conversation.