How to remove index.php from URL

Published 2 years ago by sada059

I have hosted my Laravel 5 App with Oracle Linux and I have it working fine but the problem is my URLs runs with index.php suffix. I am trying to get rid of this index,php from my URLs. My .htaccess file is in my root directory var/www/public_html (Public folder files are moved to root directory) here is the content of file.

Options -MultiViews

RewriteEngine On

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

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

the .htaccess file shows under hidden files.

pmall
pmall
2 years ago (547,295 XP)

Your app virtual host must have the public folder of your app as root directory.

martinbean

@sada059 Did you bother to search the issue before posting? This has been asked literally dozens on times on this forum alone: https://laracasts.com/discuss?q=index.php

sada059

@pmall I dont have public folder anymore I have moved all the files to the project root directory var/www/public_html

sada059

@martinbean I have gone through most of the discussions but still cant get this workin. well this link https://laracasts.com/discuss/channels/servers/urls-only-work-when-indexphp-is-used is very similar to the issue im facing the solution described was modifying my .htaccess file but still I get page not found error on URLs without index.php

sitename/ -- this works fine

sitename/index.php -- this also works fine

sitename/auth/login -- This causes a server 404

sitename/index.php/auth/login -- this works fine

Snapey
Snapey
2 years ago (957,155 XP)

daft questions;

You are using Apache?

Your .htaccess file is in the document root directory?

Create a file called test.php, containing "hello". visit sitename/test.php, what happens?

sada059

@Snapey Yes I am using Apache. The .htaccess file is in the document root directory var/www/public_html When I visit sitename/test.php I get the message "hello"

nruslan

Some of my URLs were crawled by Google with "index.php". I used the code below to redirect "bad" URLs to correct once, without index.php.


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

Please sign in or create an account to participate in this conversation.