How to remove index.php from URL 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.
Your app virtual host must have the public folder of your app as root directory.
@pmall I dont have public folder anymore I have moved all the files to the project root directory var/www/public_html
@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
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?
@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"
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]
Thanks Nruslan, It work for me.
You shouldn't have to fumble with the htaccess file it works as is.
You might need to add
RewriteBase /yoursite/
after RewriteEngine On
You need to set up folder structure correctly, which has been covered before.
Please sign in or create an account to participate in this conversation.