Laravel subdomain 500 error

2019-08-07 11:15发布

We are running on shared hosting and running laravel on main domain that is example.com , everything is working perfectly fine.

We have crated a sudbomain test.example.com by vising Subdomains manager in cPanel and pointed it's document root to /public_html/test

As soon as we visit test.example.com we get 500 Internal Server Error

Initial laravel's .htaccess is

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

We have changed.

    RewriteRule ^ index.php [L]

to

    RewriteRule ^ /index.php [L]

Now if we visit test.example.com it redirect to tests.example.com/test and everything works normally.

But we not sure why it is redirecting browser to tests.example.com/test ?

Updated

After further research we found that.

If we remove this line.

RewriteRule ^(.*)/$ /$1 [L,R=301]

Then both maindomain and subdomain working perfectly fine. But is it OK to remove this line.

In short we want to run laravel on main domain and something else on subdomain.

1条回答
2楼-- · 2019-08-07 12:17

You can add a restriction on test subdomain.
Also, you have to avoid removing trailing slash for folders (otherwise: loop -> 500 error).

Your htaccess would then become

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

    RewriteEngine On

    # Don't touch anything when coming from test subdomain
    RewriteCond %{HTTP_HOST} ^test\. [NC]
    RewriteRule ^ - [L]

    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /index.php [L]
</IfModule>
查看更多
登录 后发表回答