首页 > 解决方案 > Apache 和 TYPO3 不加载主页和后端以外的页面

问题描述

我在 Xubuntu 上使用 Apache 2 来运行 TYPO3 的多个本地实例。由于他们使用不同的 TYPO3 和 PHP 版本,我使用 fastcgi 将请求传递给 TYPO3 版本 9.5.x 的请求到相应的 php7.2-fpm。

但是,除了“主页”、TYPO3 后端和 phpinfo 之外,没有其他页面正在加载。我只收到一条原始 404 消息,看起来它来自 apache 而不是 TYPO3 本身。

我可以让页面加载的唯一方法是当我使用 pageID 和一个参数调用它们来抑制重定向到“更漂亮”的 URL 时。这和原始错误页面让我相信问题出在我的 Apache 配置而不是我的 TYPO3 设置中。似乎对特定文件(/index.php、/typo3/index.php 和 /info.php)的每次调用都有效,但路由不起作用,因为 apache 尝试将其直接解析为文件/目录.

这是有问题的虚拟主机的 apache 配置:

<VirtualHost *:80>
   ServerName test.test
   DocumentRoot /var/www/foo/bar/httpdocs

#    <FilesMatch \.php$>
#        SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost"
#    </FilesMatch>

   ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.2-fpm.sock|fcgi://localhost/var/www/foo/bar/httpdocs

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

评论部分是第一次尝试,当我注意到问题时,我在网上找到了“ProxyPassMatch”-Part 并尝试了它,但我遇到了同样的问题。

标签: phptypo3apache2typo3-9.x

解决方案


这是在默认 .htaccess 中重写的关键部分(随 TYPO3 提供):

<IfModule mod_rewrite.c>
    RewriteEngine On

    # ...         

    # If the file/symlink/directory does not exist => Redirect to index.php.
    # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
</IfModule>

重要的是所有不是文件请求的 URL 都被传递给 index.php

首先,检查显而易见的:

  1. 是否启用了 mod_write(例如a2enmod rewrite)?
  2. .htaccess 被执行了吗?如前所述,在评论中,必须设置AllowOverride 。

例如,在 VirtualHost 部分中,输入以下内容:

<Directory /var/www/foo/bar/httpdocs>
   # When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.
   AllowOverride All
</Directory>

如果这不能解决问题,您可以尝试逐步缩小问题范围:

例如,在您的 Web 根目录中创建一个带有文本“hello”的文件 /abc.txt。然后,在 TYPO3 重写块之前添加它。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /?xyz /abc.txt [L]
</IfModule>

测试 URL /abc.txt、/xyz。他们都应该显示“你好”。

这样,您可以检查重写是否正常工作(不涉及 TYPO3)。测试成功后,再次删除。

另请参阅安装指南中的故障排除,其中还提到了 mod_rewrite。

免责声明:我不知道,ProxyPassMatch但它似乎通常按照您的描述工作。


推荐阅读