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

如何在000webhost免费主机中去除Laravel项目URL中的public路径

Fixing Laravel Public Path Removal on 000webhost

I’ve run into this exact issue with 000webhost before—their server configuration has a few quirks that can break the standard Laravel setup for removing the public path. Let’s walk through the fixes step by step:

First, Double-Check Your Index.php

Make sure the index.php you renamed from server.php in your root directory has the correct file paths. Open it up and verify these lines are present (they should be by default, but it’s worth confirming):

if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

This ensures the file correctly points to your public/index.php entry point.

Update Your .htaccess with RewriteBase

000webhost often requires explicitly setting the RewriteBase directive for mod_rewrite rules to work properly. Replace your current root .htaccess with this modified version:

Options -MultiViews -Indexes
RewriteEngine On
# Explicitly set RewriteBase for 000webhost's server configuration
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

The key addition here is RewriteBase /—this tells the server where to anchor all rewrite rules, which fixes path mismatches that often happen on 000webhost.

Clear Browser Cache & Test in Incognito

Since you’ve already tried 301 redirects, your browser might have cached the old public path. Test your site in an incognito window or clear your browser’s cache to ensure you’re seeing the latest changes.

Verify 000webhost’s URL Rewriting Settings

Log into your 000webhost control panel and navigate to your site’s settings. Look for an option like SEO Friendly URLs or Mod Rewrite—make sure this is enabled. Some accounts have this turned off by default, which will ignore your .htaccess rules entirely.

Check Your Directory Structure

Ensure your Laravel project is directly placed in 000webhost’s root directory (usually named public_html). If you uploaded it into a subfolder (e.g., public_html/laravel), you’ll need to adjust the RewriteBase to match that subfolder path, like RewriteBase /laravel/.

After following these steps, your site should load without needing the public segment in the URL.

内容的提问来源于stack exchange,提问作者saqib javed

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 14:54:09