【问题标题】:How can I get my FuelPHP application working in a subdirectory?如何让我的 FuelPHP 应用程序在子目录中工作?
【发布时间】:2013-09-12 20:26:49
【问题描述】:

我有一个 FuelPHP 应用程序,我正在尝试设置它以扩展现有网站(我们称之为 example.com)。 FuelPHP 安装在DocumentRoot 中名为listings 的目录中。但是,应用程序的主文件index.php 位于listings 的子目录public,因此index.php 文件的实际路径是<DocumentRoot>/listings/public/index.php。应用程序的静态资产(JavaScript、CSS 和图像)也在 public 目录的子目录中。

我希望人们能够通过/properties 访问该应用程序。此外,还会有对其他页面的请求(如/properties/admin)以及对静态资产的请求(如/properties/assets/css/style.css)。

我已经完成了 90% 的工作。 DocumentRoot 中的 .htaccess 文件如下所示:

RewriteEngine On
RewriteRule ^properties/?(.*)$ /listings/public/index.php/$1 [L]

public 目录中,还有另一个.htaccess 文件,如下所示:

Options +FollowSymLinks -Indexes
RewriteEngine on

# Send request via index.php (not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.*)$ index.php/$1 [L]

我将 FuelPHP 配置中的 $base_url 设置为 http://example.com/properties/。静态资产的所有 URL 都以我期望的方式显示,例如,我的 bootstrap.css 文件的路径显示为 http://example.com/properties/assets/css/bootstrap.css。这是我所期望的。然而,Apache 没有抓取静态资源,而是通过 FuelPHP index.php 文件运行请求,导致 404。

我想我需要在DocumentRoot 中的.htaccess 文件中添加一个RewriteCond,但我不确定这是否正确,或者RewriteCond 会是什么样子。

如何调整我的 .htaccess 文件,以便能够访问静态资产,例如实际位于 <DocumentRoot>/listings/public/assets/css/bootstrap.csshttp://indyapm.com/properties/assets/css/bootstrap.css

【问题讨论】:

    标签: apache .htaccess fuelphp


    【解决方案1】:

    我相信你想要的是一个 RewriteBase

    RewriteEngine On # after this
    RewriteBase /properties/ # insert this
    

    也就是说,使用正确的基本 url 设置您的主配置应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-26
      • 2019-10-02
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      相关资源
      最近更新 更多