【问题标题】:can't access subdomain for laravel htaccess?无法访问 laravel htaccess 的子域?
【发布时间】:2014-08-20 12:04:28
【问题描述】:

在我的域公共目录是 laravel 公共目录。所以有 index.php 和 htaccess 文件。但我想访问mydomain.com/demo/,其中demo 是一个文件夹。由于路由重写,它总是将我重定向到我的主页mydomain.com。那么如何访问 mydomain.com 中的文件夹。我的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>

提前致谢

【问题讨论】:

    标签: .htaccess laravel


    【解决方案1】:

    在演示目录中创建一个单独的 .htaccess 文件以覆盖根目录中的 .htaccess 文件。

    Order Allow,Deny Allow from all

    【讨论】:

      【解决方案2】:

      在演示目录中创建一个单独的 .htaccess(如 Brian Dillingham 所说)文件以覆盖根目录中的 .htaccess 文件。 但是把使用代码放在下面:

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

      另外,你可以参考答案:https://stackoverflow.com/a/38068912

      【讨论】:

        【解决方案3】:

        对于那些使用公共域但 Laravel 目录位于子目录中的人。您可能具有以下文件夹结构:

        - / <-- directory your domain (e.g. "https://example.com") points to
        - some_subfolder1/
        - some_subfolder2/
        - laravel_project/
            - ...
            - public/
                - .htaccess <-- File one has to modify
                - index.php
                - ...
        

        前端控制器的 .htaccess 文件 RewriteRule 如下所示:

        RewriteRule ^ laravel_project/public/index.php [L]
        

        所以你最终会得到:

        <IfModule mod_rewrite.c>
            <IfModule mod_negotiation.c>
                Options -MultiViews
            </IfModule>
        
            RewriteEngine On
            RewriteBase /
        
            # Redirect Trailing Slashes If Not A Folder...
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)/$ /$1 [L,R=301]
        
            # Handle Front Controller...
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ laravel_project/public/index.php [L]
        </IfModule>
        

        另外,我还修改了.env-File为APP_URL参数:

        APP_URL=https://example.com/laravel_project/public
        

        此外,您可能会考虑将 laravel 项目文件(尽管来自公用文件夹)移到此文件树之外。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-12-20
          • 2020-01-20
          • 2016-01-18
          • 2011-08-15
          • 2014-02-05
          • 1970-01-01
          • 1970-01-01
          • 2016-06-21
          相关资源
          最近更新 更多