Apache,如何处理像标准URL这样的未知php文件?

我有一个Symfony网站,我已经重命名了主入口点,因此“索引.php”无法访问,也无法被搜索电机索引。它运行良好。但是,当我尝试访问此文件时,我没有得到一个404文件,找不到,这个404页面由Apache处理,而不是由应用程序处理,它是标准的404页面:


Not Found

The requested URL was not found on this server.

我希望像/index.php这样的URL(实际上*.php)由Symfony应用程序处理,以显示具有良好布局的自定义错误页面。我的虚拟主机看起来像这样,我试图添加一个“目录索引”指令,但没有成功。


# configuration/vhosts/prod/mywebsite.com-le-ssl.conf

<IfModule mod_ssl.c>

    <VirtualHost *:443>

        ServerName www.mywebsite.com

        DocumentRoot /var/www-protected/mywebsite.com/public


        <Directory /var/www-protected/mywebsite.com/public>

            AllowOverride All

            Require all granted

            FallbackResource /my-secret-entry-point.php

        </Directory>


        RedirectMatch 404 /\.git


        ErrorLog /var/log/apache2/mywebsite.com_error.log

        CustomLog /var/log/apache2/mywebsite.com_access.log combined


        RewriteEngine on

        RewriteCond %{SERVER_NAME} =mywebsite.com

        RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


        SSLCertificateFile /etc/letsencrypt/live/www.mywebsite.com/fullchain.pem

        SSLCertificateKeyFile /etc/letsencrypt/live/www.mywebsite.com/privkey.pem

        Include /etc/letsencrypt/options-ssl-apache.conf

    </VirtualHost>

</IfModule>


鸿蒙传说
浏览 130回答 1
1回答

一只斗牛犬

这可以通过mod_rewrite来完成,回复:301Options +FollowSymLinksDirectoryIndex index.phpRewriteEngine OnRewriteBase /RewriteCond %{THE_REQUEST} ^.*/index\.php&nbsp;RewriteRule ^(.*)index.php$ /$1 [R=301,L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]默认错误文档可用于将错误代码分派给 PHP:ErrorDocument 404 https://mywebsite.com/error/page/404ErrorDocument 500 https://mywebsite.com/error/page/500然后,人们仍然可以发送任何想要的内容 - 或者只是显示具有相同标题的页面。header()
打开App,查看更多内容
随时随地看视频慕课网APP