Laravel subdomain 500 error

家住魔仙堡 提交于 2019-12-11 07:04:08

问题


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:


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>


来源:https://stackoverflow.com/questions/28013448/laravel-subdomain-500-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!