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

Laravel 5.4部署至000webhost后路由无法访问问题求助

Fixing Laravel 404 on SignUp/SignIn in 000webhost

Let's walk through the most likely fixes for this issue—shared hosts like 000webhost often have specific quirks with Laravel's deployment structure that cause routing 404s, even when everything works locally.

1. Fix Your Website Root Directory (Most Common Culprit)

000webhost defaults to using public_html as your website's root directory, but Laravel requires its own public folder to be the root. Here's how to fix this:

  • Log into your 000webhost control panel
  • Navigate to your domain's settings (usually under "Website" or "Domains")
  • Change the root directory from public_html to public_html/public
  • Save the changes and test your sign-up/sign-in forms again

This ensures all requests (like /signUp) are routed through Laravel's public/index.php file, which handles your application's routing.

2. Verify Your .htaccess File

Laravel relies on the .htaccess file in the public folder to redirect all requests to index.php. Make sure your public_html/public/.htaccess has the default Laravel content:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # 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]
</IfModule>

If you copied .htaccess to the public_html root instead, it won't work once you set the root directory to public_html/public.

3. Check Form Action & Route Method Mismatch

Your routes are defined as POST requests, which means accessing /signUp directly via the browser (a GET request) will throw a 404—that's expected behavior. To confirm your form is sending the right request:

  • Right-click your sign-up form on the live site and select "View Page Source"
  • Check the action attribute of the <form> tag—it should match https://myprojectblog.000webhostapp.com/signUp
  • Ensure the form's method is set to POST (which your code shows it is)

4. Clear Route Cache & Re-Upload Files

Local Laravel projects often cache routes, which can cause mismatches when deployed. Do this locally first:

php artisan route:clear
php artisan config:clear

Then re-upload all your Laravel files to the server (especially the bootstrap/cache directory) to ensure no stale cached data is causing issues.

5. Confirm File Permissions

Make sure the following directories have correct read/write permissions (usually 755 or 775 depending on your host's setup):

  • Blog/storage
  • Blog/bootstrap/cache
    Incorrect permissions can sometimes break routing or application loading, even if it's not the direct cause of your 404.

If none of these fixes work, double-check that your public_html/public/index.php paths are correct:

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

This path looks right (since __DIR__ refers to public_html/public, ../Blog points to your core Laravel files), but it's worth verifying the file structure again to ensure no typos.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 03:56:53