【问题标题】:Fat Free Framework configurations on a subdomain子域上的 Fat Free Framework 配置
【发布时间】:2014-09-20 16:31:15
【问题描述】:

我正在尝试在子域上部署 Fat Free Framework 应用程序。它在我的本地服务器上运行良好,但是在将其部署到实时站点的子域上时,我得到了一个空白页面。我相信我的配置(.htaccess,config/routes)错误,但我尝试了几个,但无法让它工作。我的配置是:

.routes 文件

[routes]
GET /games/@gameid/@move = WebPage->getgames

.config 文件

[globals]
AUTOLOAD = app/;third_party/;third_party/phpQuery/
DEBUG = 0
UI = views/
ENCODING = utf-8
LOGS= tmp/cache/

.htaccess 文件

#mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,QSA]

#Hotlinking Protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?subdomain.domain.com/.*$ [NC]
RewriteRule \.(js|css|jpg|gif|png|bmp|mp4|3gp|m4a|m4r|aac|mp3|ogg|wave)$ - [F]

#PHP code in HTML file
AddType fcgid-script .php .htm .html .phtml

我使用的是 PHP 版本 5.3.28 Apache 2.3.7

文件夹结构

subdomain.domain.com(子域文件夹)

  • .htaccess 文件
  • index.php 文件
  • 应用文件夹
  • db 文件夹
  • 查看文件夹
  • 第三方文件夹
  • tmp 文件夹

在我的本地服务器上,我有这样的 .htaccess 文件

Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]

【问题讨论】:

  • 您本地服务器上的.htaccess 文件是什么?这似乎是错误的:RewriteBase /subdomain.domain.com.
  • 是的,正如 JakeGould 所说,我已将 .htaccess 文件编辑为 \,但在尝试访问 subdomain.domain.com/games/01test20140322/1 时仍会出现空白页。 .htaccess 文件与 index.php 文件位于子域文件夹中。包含我的配置和路由的应用程序文件位于 /subdomain/app 下方的文件夹中
  • 你能提供它工作的 URL 以及它工作的 .htaccess 吗?否则几乎没有人可以帮助您。
  • 就像我之前所说的,它可以在我的本地服务器上运行(在虚拟主机上,而不是子域上)。我不知道我是否正确回答了您的问题,但我试图重现上面的文件夹结构。唯一的更正是我的子域文件夹在我的网络主机文件中被命名为 subdomain.domain.com
  • 您向我们展示了不起作用的配置,但是在您的本地设置上确实有效的配置是什么?具体来说,您在本地主机上成功访问的 URL 是什么?在本地主机上工作的 .htaccess 是什么?

标签: php .htaccess subdomain fat-free-framework


【解决方案1】:

这似乎不正确:

RewriteBase /subdomain.domain.com

我会把它改成这样:

RewriteBase /

原因是RewriteBase 仅指服务器本身的 URL 基础,而不是“左侧”的任何内容。意思是这是否是您的主站点 URL:

http://subdomain.domain.com

设置RewriteBase /subdomain.domain.com 意味着规则只会作用于以下网址:

http://subdomain.domain.com/subdomain.domain.com

为了更清楚一点,如果代码在基本 URL 的“右侧”路径上运行,则只会调整 RewriteBase /(然后是相应的 RewriteRule)。因此,假设您将它安装在目录 mycoolapp/ 中,并且您希望它可以像这样访问:

RewriteBase /mycoolapp/

然后您必须像这样为index.php 调整RewriteRule

RewriteRule . /mycoolapp/index.php [L,QSA]

编辑:基于您为本地设置提供.htaccess,您的mod_rewrite 有此:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]

但是在您的子域设置中,您有这个:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,QSA]

为什么会有根本的不同?只需使用本地设置中的 mod_rewrite 即可。在您的子域设置中特别去掉这一行:

RewriteBase /

并改变这一行:

RewriteRule . /index.php [L,QSA]

变成这样:

RewriteRule .* index.php [L,QSA]

所以最终的子域.htaccess 应该是这样的:

#mod_rewrite on
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]

#Hotlinking Protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?subdomain.domain.com/.*$ [NC]
RewriteRule \.(js|css|jpg|gif|png|bmp|mp4|3gp|m4a|m4r|aac|mp3|ogg|wave)$ - [F]

#PHP code in HTML file
AddType fcgid-script .php .htm .html .phtml

【讨论】:

  • 好的。我按照您的建议编辑了 .htaccess 文件,但仍然得到一个空白页。我正在尝试根据上述路线访问subdomain.domain.com/games/01test20140322/1。谢谢
  • 这个 URL subdomain.domain.com/games/01test20140322/1 的绝对基数是什么?是那个完整的网址吗?还是subdomain.domain.com/games/01test20140322?还是subdomain.domain.com/games
  • 绝对基础??我对这个术语有点困惑,但我正在尝试访问 subdomain.domain.com/games/01test20140322/1,就像我上面说的那样。 /01test20140322 路由到“gameid”,/1 是路由文件中指定的“移动”。
  • 没有线索。您可能想检查她的错误日志。您可以检查服务器输出的标头——看看这是否能说明问题——通过这样做,curl -I http://subdomain.domain.com/games/01test20140322/1
  • 现在工作正常。将之前问题的原因发布为答案。
【解决方案2】:

显然这是由 php 错误引起的,因为我关闭了显示错误,所以我看不到它。在我上传全新安装的应用程序并获得后,它被我的虚拟主机的支持人员发现了

内部服务器错误 致命错误:语法错误,意外'['

特别是我的网络托管支持人员说这与 PHP 数组取消引用有关。我在下面引用部分内容

..看起来你的脚本的一部分正在使用数组解引用 它适用于 PHP 5.4+,并且..

所以我们切换到 PHP 5.4+,一切顺利。

顺便说一句,我使用了以下 .htaccess

#mod_rewrite on
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]

没有压力,没有大惊小怪。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    相关资源
    最近更新 更多