Home >Backend Development >PHP Tutorial >How Can I Remove the \'/public/index.php\' Prefix from My Laravel URLs?
Introduction
By default, Laravel generates URLs with the "/public/index.php/" prefix. This additional path component can be unnecessary and distracting, especially in production environments. This article explores two approaches to remove it.
Option 1: Using .htaccess
Create or edit the .htaccess file in the Laravel root directory and add the following code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/ [L] </IfModule>
This rule rewrites all incoming requests to the "public" directory, effectively removing the "/public/index.php/" prefix.
Option 2: Moving Files and Editing Directives
'public' => __DIR__.'/../../',
require __DIR__.'/laravel_code/bootstrap/autoload.php'; $app = require_once __DIR__.'/laravel_code/bootstrap/start.php';
This approach physically moves the files out of the "public/" directory and adjusts the path configuration accordingly.
The above is the detailed content of How Can I Remove the \'/public/index.php\' Prefix from My Laravel URLs?. For more information, please follow other related articles on the PHP Chinese website!