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

murlidharfichadia@gmail.com's avatar

Remove index.php from url in Laravel 5.4 - CentOS 6

I have tried almost all the solutions on internet regarding this issue.

I have moved my Laravel project from Windows 10 to linux CentOS 6. I tried to change project structure in two different manner but both face the issue.

I am trying to remove index.php from [www.example.com]/index.php/[routes url]. I don't have access to root or sudo command as this project is being installed in University server. But I can request IT admin for tasks that require root access.

I am currently in /home/cs4/username (folder). My current project structure is:

 blog (folder)
 - contains all the Laravel framework files other than public folder

 public_html (folder)
 - contains all the files of laravel public folder plus 
 - .htaccess file created

.htaccces file contains below code:

 # Redirect Trailing Slashes...
 #RewriteRule ^(.*)/$ $1 [L,R=301]

 RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
 RewriteCond %{REQUEST_URI} !/system/.* [NC]
 RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

 # Handle Front Controller...
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteRule ^ index.php [L]
 RewriteRule ^(.*)$ /index.php/$1 [L]

I have replaced 2 lines of index.php file which is in public_html folder

from these

 require __DIR__.'/../bootstrap/autoload.php';
 $app = require_once __DIR__.'/../bootstrap/app.php';

to

 require __DIR__.'/../blog/bootstrap/autoload.php';
 $app = require_once __DIR__.'/../blog/bootstrap/app.php';

Issue is that http://example.ac.uk/~username/ loads the project but for all other url's I have to add index.php for example: http://www.example.ac.uk/~username/index.php/login instead of http://www.example.ac.uk/~username/login similarly for all other url's.

I also tried to put entire project inside public_html folder, the directory structure was:

 public_html
 -entire project files and folders
 -public folder

but then 2 issues:

  1. all the server files like : .env and other code is exposed causing security risk
  2. I am forced to have public/index.php in the url.

for example: http://www.example.ac.uk/~username/public/index.php/login instead of http://www.example.ac.uk/~username/login similarly for all other url's.

0 likes
5 replies
RayC's avatar

Have you changed the path in the server.php file to point to the index.php file?

if ($uri !== '/' && file_exists(__DIR__.'../public_html'.$uri)) {
    return false;
}

require_once __DIR__.'../public_html/index.php';

And change the .htaccess file to look in the blog folder

 # Redirect Trailing Slashes...
 #RewriteRule ^(.*)/$ $1 [L,R=301]

 RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
 RewriteCond %{REQUEST_URI} !/blog/.* [NC]
 RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

 # Handle Front Controller...
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteRule ^ index.php [L]
 RewriteRule ^(.*)$ /index.php/$1 [L]

Hope this help.

Regards,

Ray

murlidharfichadia@gmail.com's avatar

@CodebyRay Hi Ray, I did exactly as you suggested replaced .htaccess file content and changed /public to ../public_html in 2 places (server.php).

I am not seeing any change. Is the fault of httpd.conf ? do I need to do something with regards to VirtualHost AllowOverride All or so?

What is frustrating is that I don't see any errors thrown. I don't know how to debug this index.php issue and how to pinpoint the cause. I might do some unnecessary changes which could create more problems. Any guidance on how do I find what is causing this? before finding a solution.

murlidharfichadia@gmail.com's avatar

@hendranucleo I dont have access to httpd.conf file. I need to request admin to do that but is there any other possible way to do it without the need to modify httpd.conf file? Also, How do I make sure or do some test to find out if httpd.conf needs to be set to AllowOverride "All" instead of "None".

I want to do some testing to really find out if that is the case. Can I do some test using a script? like we do phpinfo(); to find out info about php version.

Please or to participate in this conversation.