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
Release: 2024-11-28 03:27:19
Original
687 people have browsed it

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>
Copy after login
  • 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__.'/../../',
Copy after login

index.php:

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

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template