Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hakhsin's avatar

The path of subdomains don't work

Hi, I have a shared host. In local host everything work good but when I upload my project on my host the path of subdomain doesn't work. I mean when I open www.example.com or api.example.com they work but if I want to open api.example.com/login or any other paths I get 404 error. Why do happen those? What do I do?

0 likes
8 replies
Sinnbeck's avatar

How does the subdomains work? Do you get the frontpage or?

1 like
hakhsin's avatar

Hi @sinnbeck, I don't know what is frontpage. I google it but google give me Microsoft Front Page. Can you describe it for me, please?

Here is my RouteServiceProvider:

  /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::name('web.')
            ->middleware(['web'])
            ->domain(subdomain(env('WEB_SUBDOMAIN')))
            ->namespace($this->namespace . '\Web')
            ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::middleware(['api'])
            ->domain(subdomain(env('API_SUBDOMAIN', 'api')))
            ->namespace($this->namespace . '\Api')
            ->group(base_path('routes/api.php'));
    }
Sinnbeck's avatar

By frontpage I mean, your own pages first page .. If you go to the site without www, do you see the same?

1 like
Sinnbeck's avatar

You said

I mean when I open www.example.com or api.example.com they work

But you are getting 404 for them? Which is it?

Sorry if it is hard to understand. What I am asking is, if you visit www.example.com and example.com do you see the same?

1 like
hakhsin's avatar

@sinnbeck when I open example.com, I get 404. I meant www.example.com and example.com are different for my app.

hakhsin's avatar
hakhsin
OP
Best Answer
Level 6

Hi @sinnbeck, I found out this:

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

It is good in your mind? Do you have a recommendation for it?

Please or to participate in this conversation.