【问题标题】:Laravel subdomain 500 errorLaravel 子域 500 错误
【发布时间】:2015-03-16 19:09:53
【问题描述】:

我们在共享主机上运行并在 example.com 的主域上运行 laravel,一切正常。

我们通过访问 cPanel 中的 子域管理器 创建了一个 sudbomain test.example.com,并将其文档根目录指向 /public_html/test

我们一访问test.example.com,就会收到500 Internal Server Error

初始 laravel 的 .htaccess 是

<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>

我们变了。

    RewriteRule ^ index.php [L]

    RewriteRule ^ /index.php [L]

现在如果我们访问test.example.com,它会重定向到tests.example.com/test,一切正常。

但我们不确定它为什么将浏览器重定向到tests.example.com/test

更新

经过进一步研究,我们发现。

如果我们删除这一行。

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

然后主域和子域都可以正常工作。但是去掉这行可以吗?

简而言之,我们想在主域上运行 laravel,在子域上运行其他东西。

【问题讨论】:

  • 如果你去 tests.example.com/public 怎么办?
  • test.example.com 中没有任何内容,只需将index.phpphpinfo(); 一起归档即可。
  • 你的意思是/public_html/test里面没有laravel?只是 index.php ?
  • @EimantasGabrielius 如果我们删除RewriteRule ^(.*)/$ /$1 [L,R=301],那么子域和主域都可以正常工作。但不确定远程这个是否可以。
  • 是的 /public_html/test 文件夹不包含 laravel,它只包含 index.php 文件。 Laravel 安装在/public_html(主域)

标签: php apache .htaccess laravel-4


【解决方案1】:

在我的例子中,我在子域 public_html 文件夹中没有 .htaccess 文件,所以如果您正在使用子域,只需将 .htaccess 文件从原始域复制到子域文件夹(在这种情况下是完全相同的应用程序)。

【讨论】:

    【解决方案2】:

    您可以对test 子域添加限制。
    此外,您必须避免删除文件夹的尾部斜杠(否则:循环 -> 500 错误)。

    你的 htaccess 会变成

    <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>
    

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 2023-03-22
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 2018-02-28
      • 1970-01-01
      相关资源
      最近更新 更多