You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5.5本地部署:如何绕过/public目录直接访问项目

How to Access Laravel 5.5 Project Without /public in URL (Localhost)

Got it, let's get this sorted so you can reach your Laravel 5.5 project directly via http://localhost/my_laravel/ instead of having to append /public every time. Here are two reliable methods tailored for local setups like XAMPP or WAMP:

Method 1: Use .htaccess Rewrite (Quick & Simple for Apache)

This is the fastest fix if you want to keep your existing URL structure:

  • Head to your project root folder (my_laravel). If there’s no .htaccess file here, create a new one.
  • Open the .htaccess file and paste this code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
  • Save the file and restart your Apache server. Now when you visit http://localhost/my_laravel/, it’ll automatically route to the /public directory behind the scenes.

Quick check: Make sure Apache’s mod_rewrite module is enabled. Open your httpd.conf file (in XAMPP/WAMP’s Apache folder) and remove the # from this line if it’s present:

#LoadModule rewrite_module modules/mod_rewrite.so

Restart Apache to apply the change.

Method 2: Configure Virtual Host (Cleaner & Scalable)

If you prefer a more professional local URL (like http://mylaravel.local) and want a setup closer to production, try this:

  1. Open Apache’s httpd-vhosts.conf file (usually in xampp/apache/conf/extra/ or wamp/bin/apache/apacheX.X.X/conf/extra/).
  2. Add this virtual host config at the end:
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/my_laravel/public"  # Replace with your actual project public path
    ServerName mylaravel.local
</VirtualHost>
  1. Edit your system’s hosts file:
    • Windows: Go to C:\Windows\System32\drivers\etc\hosts (you’ll need admin rights to edit).
    • Mac/Linux: Open /etc/hosts in a text editor with sudo privileges.
  2. Add this line to the hosts file:
127.0.0.1 mylaravel.local
  1. Save all files and restart Apache. Now you can access your project via http://mylaravel.local directly—no need for localhost/my_laravel at all!

Either method will solve your problem. The first is perfect for keeping your current URL, while the second gives you a cleaner, production-like local environment.

内容的提问来源于stack exchange,提问作者Amit Kumar Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:51:04