php - 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 并尝试了它,但我遇到了同样的问题。
解决方案
这是在默认 .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
首先,检查显而易见的:
- 是否启用了 mod_write(例如
a2enmod rewrite
)? - .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
但它似乎通常按照您的描述工作。
推荐阅读
- r - 当我尝试在 R 中创建时间受限的集群时出现错误
- html - CSS 宽度属性无法正常工作
- python - 如何在平板电脑中查看电池状态
- apache-spark - Py4JError:调用 o90.fit 时出错
- javascript - 为什么这个反应/javascript“removeEventListener”不删除监听器?
- vb.net - 学习VB并有基本的数学语法错误
- python - 为什么会出现消息str object Has no attribute id?
- monaco-editor - Monaco Editor:通过编辑器配置库
- java - 作为对象的 HashMap 值具有被错误值覆盖的属性
- laravel - 解析错误:语法错误、意外的 '__construct' (T_STRING)、期望函数 (T_FUNCTION) 或 const (T_CONST)