【问题标题】:Apache and TYPO3 not loading pages other than home-page and backendApache 和 TYPO3 不加载主页和后端以外的页面
【发布时间】:2020-09-15 07:41:50
【问题描述】:

我在 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并尝试了它,但我遇到了同样的问题。

【问题讨论】:

  • 您的 TYPO3 文档根目录中是否有 TYPO3 的 .htaccess? TYPO3 附带了一个适当的 .htaccess,它具有说话 URL 的必要重写规则。
  • @PeterKraume 是的,我有,我没有改变任何东西。
  • 可能需要加RewriteBase /
  • @PeterKraume 我需要在哪里添加?
  • RewriteEngine on之后的.htaccess文件中。

标签: php typo3 apache2 typo3-9.x


【解决方案1】:

这是重写默认 .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 执行了吗?如前所述,在 cmets 中,必须设置 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>

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

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

另请参阅安装指南中的Troubleshooting,其中还提到了 mod_rewrite。

免责声明:我不知道ProxyPassMatch,但它似乎与您所描述的一样。

【讨论】:

  • 重写模块处于活动状态,但是我不知道在哪里设置 AllowOverride,根据文档,它只能在我没有的 部分中设置
  • 我在答案中添加了一个示例。只需使用您网站的根目录(您已将其用于 DocumentRoot)创建一个目录部分。在那里,放置 AllowOverride。替代解决方案:将 .htaccess 中的配置移动到 apache 的配置文件中。这样您就不需要覆盖配置。 .htaccess 仅在人们无法直接访问 Web 服务器配置的共享托管环境中是必需的。
猜你喜欢
  • 1970-01-01
  • 2011-09-02
  • 2020-10-04
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多