Basically I need to remove index.php
or public/index.php
from the the generated URL in laravel, commonly path is localhost/public/index.php/someWordForRoute
, It should be something like localhost/someWordForRoute
htacces
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
app/config/app.php
'url' => 'http://localhost',
how can I change that?
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 !! :)
As per Laravel 5.3 the above things will not work properly, but please be calm and follow below steps:
Step 1. Go to inside of laravel project
Step 2. Make one random directory/folder eg. laravelcode
Step 3. Move all the folder and files(Except public folder)
Step 4. Move all the folder and files which are inside the public folder to the laravel project
Step 5. Now inside the laravel project there is index.php file, please open that and change the folder paths for bootstrap as per new path like previously it was "require DIR.'/../bootstrap/autoload.php';" now it will become to "require DIR.'/laravelcode/bootstrap/autoload.php';"
That's it just run your url without public and index.php like below http://localhost/blog/
HERE ARE SIMPLE STEPS TO REMOVE PUBLIC IN URL (Laravel 5)
1: Copy all files form public folder and past them in laravel root folder
2: Open index.php and change
From
To
And
To
In laravel 4 path 2 is
$app = require_once __DIR__.'/bootstrap/start.php';
instead of$app = require_once __DIR__.'/bootstrap/app.php';/app.php
That is it.
Option 1: Use .htaccess
If it isn't already there, create an .htaccess file in the Laravel root directory. Create a
.htaccess
file your Laravel root directory if it does not exists already. (Normally it is under yourpublic_html
folder)Edit the .htaccess file so that it contains the following code:
Now you should be able to access the website without the "/public/index.php/" part.
Option 2 : Move things in the '/public' directory to the root directory
Make a new folder in your root directory and move all the files and folder except public folder. You can call it anything you want. I'll use "laravel_code".
Next, move everything out of the public directory and into the root folder. It should result in something somewhat similar to this:
After that, all we have to do is edit the locations in the
laravel_code/bootstrap/paths.php
file and theindex.php
file.In
laravel_code/bootstrap/paths.php
find the following line of code:And change them to:
In
index.php
, find these lines:And change them to:
Source: How to remove /public/ from URL in Laravel
This likely has very little to do with Laravel and everything to do with your Apache configs.
Do you have access to your Apache server config? If so, check this out, from the docs:
The reason why I mention this first is because it is best to get rid of
.htaccess
completely if you can,and use aDirectory
tag inside aVirtualHost
tag. That being said, the rest of this is going to assume you are sticking with the.htaccess
route for whatever reason.To break this down, a couple things could be happening:
I note, perhaps pointlessly, that your file is named
.htacces
in your question. My guess is that it is a typo but on the off chance you overlooked it and it is in fact just missing the second s, this is exactly the sort of minor error that would leave me banging my head against the wall looking for something more challenging.Your server could not be allowing
.htaccess
. To check this, go to your Apache configuration file. In modern Apache builds this is usually not in one config file so make sure you're using the one that points to your app, wherever it exists. Changeto
As a followup, the Apache documents also recommend that, for security purposes, you don't do this for every folder if you are going to go for
.htaccess
for rewriting. Instead, do it for the folders you need to add.htaccess
to.Do you have
mod_rewrite
enabled? That could be causing the issues. I notice you have the tag at the top<IfModule mod_rewrite.c>
. Try commenting out those tags and restart Apache. If you get an error then it is probably because you need to enablemod_rewrite
: How to enable mod_rewrite for Apache 2.2Hope this helps. I've named some of the most common issues but there are several others that could be more mundane or unique. Another suggestion on a dev server? Re-install Apache. If possible, do so from a different source with a good tutorial.
I just installed Laravel 5 for a project and there is a file in the root called
server.php
.Change it to
index.php
and it works or type in terminal: