Home >Backend Development >PHP Tutorial >How Can I Remove \'public/index.php\' from My Laravel URLs?

How Can I Remove \'public/index.php\' from My Laravel URLs?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-28 03:27:19702browse

How Can I Remove

Clean Up Laravel URLs

Q: How can I remove the "public/index.php" segment from Laravel-generated URLs?

Option 1: Modify .htaccess

  • Create or edit the .htaccess file in the Laravel root directory.
  • Add the following code:
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule ^(.*)$ public/ [L]
</IfModule>
  • This configuration automatically intercepts requests and redirects them to the public folder.

Option 2: Rearrange Directory Structure

  • Create a new root folder and move all files and folders except the public directory into it.
  • Edit the paths.php and index.php files to reflect the new directory structure:

paths.php:

'app' => __DIR__.'/../app',
'public' => __DIR__.'/../../',

index.php:

require __DIR__.'/laravel_code/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel_code/bootstrap/start.php';

The above is the detailed content of How Can I Remove \'public/index.php\' from My Laravel URLs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn