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:
all the server files like : .env and other code is exposed causing security risk
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.