I need to remove index.php
or public/index.php
from the generated URL in Laravel; commonly path is localhost/public/index.php/someWordForRoute
, It should be something like localhost/someWordForRoute.
.htaccess
<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?
One way to get rid of it, is to check the route in Laravel and issue a redirect there if needed. Here's one way to do this in app/Providers/RouteServiceProvider. php . This will redirect any URL with index.
The first reason why index. php appears in the URL might be because the structure of permalinks is not set properly in WordPress Settings. So to verify if the structure of permalinks is set properly, let's check the permalink tab in WordPress Dashboard.
To remove the “index. php” from your site's URLs, you will first need to make sure your server is set up to pass would-be 404 requests off to Craft's index. php file behind the scenes. If you're running Apache, you can do that by creating a redirect in your site's .
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 your public_html
folder)
Edit the .htaccess file so that it contains the following code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>
Now you should be able to access the website without the "/public/index.php/" part.
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 the index.php
file.
In laravel_code/bootstrap/paths.php
find the following line of code:
'app' => __DIR__.'/../app', 'public' => __DIR__.'/../public',
And change them to:
'app' => __DIR__.'/../app', 'public' => __DIR__.'/../../',
In index.php
, find these lines:
require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/start.php';
And change them to:
require __DIR__.'/laravel_code/bootstrap/autoload.php'; $app = require_once __DIR__.'/laravel_code/bootstrap/start.php';
Source: How to remove /public/ from URL in Laravel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With