【问题标题】:Laravel 4 in subfolder without "public" in the url子文件夹中的 Laravel 4,网址中没有“公共”
【发布时间】:2015-03-11 09:04:55
【问题描述】:

我有一个 Laravel 4 应用程序,它在 XAMPP 上本地运行良好。

我已将其上传到域 - domain.com -(由 godaddy 托管)并将其放在 hcr 文件夹中。

hcr/app/config/app.php 我有

'url' => 'http://domain.com/hcr',

hcr/public/.htaccess 我有

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

    RewriteEngine On  
    RewriteBase /hcr

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

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

hcr/.htaccess 我有

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /hcr
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

从 url 中删除 public

我可以访问http://domain.com/hcr/ 并加载页面(没有样式、图像等)。 但是所有其他指向页面、图像、css、js……的链接都是错误的。 例如,它们链接到

http://domain.com/css/styles.css

而不是链接到

http://domain.com/hcr/css/styles.css

即,所有链接中都缺少“hcr”。

如果我去

http://maintimeline.com/hcr/public/

一切正常,但我的网址中有“公共”,我想删除它。

那么,如何使用 .htaccess 文件从 url 中删除“public”?

【问题讨论】:

    标签: apache .htaccess mod-rewrite laravel-4


    【解决方案1】:

    按照这些简单的步骤进行

    1. move all files from public directory to root /laravel/ now, no need of public directory, so optionally you can remove it now
    2. now open index.php and make following replacements
    
    require DIR.'/../bootstrap/autoload.php';
    
     to
    
     require DIR.'/bootstrap/autoload.php';
    
     and
    
     $app = require_once DIR.'/../bootstrap/start.php';
    
     to
    
     $app = require_once DIR.'/bootstrap/start.php';
    
     3. now open bootstrap/paths.php and change public directory path:
     'public' => DIR.'/../public',
    
     to
    
     'public' => DIR.'/..',
    

    【讨论】:

    • 感谢您的回复。这是从 url 中删除“public”文件夹的另一种解决方案。我对此很清楚。但这不是我想要的。我想让它与 .htaccess 文件一起工作,并理解为什么它现在不能工作......
    猜你喜欢
    • 2016-01-24
    • 2018-04-14
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2018-07-31
    • 2021-11-01
    • 2019-07-28
    • 2023-03-03
    相关资源
    最近更新 更多