简体   繁体   English

Symfony 项目仅适用于主页。 当我导航到其他页面时,Apache 返回 404

[英]Symfony project works only homepage. When I navigate to the other pages Apache returns 404

A have symfony5 project.一个有 symfony5 的项目。 When I hosted to server I changed the default host path from https://example.com to https://example.com/public , because index.php is in /public folder.当我托管到服务器时,我将默认主机路径从https://example.com更改为https://example.com/public ,因为 index.php 位于 /public 文件夹中。 From then my site works only on the homepage.从那时起,我的网站只能在主页上运行。 When I navigate to the other pages Apache returns 404. "The requested URL /bio/ was not found on this server".当我导航到其他页面时,Apache 返回 404。“在此服务器上找不到请求的 URL /bio/”。 Everything works on localhost but not on the host.一切都在本地主机上运行,​​但不在主机上运行。

You should change the DocumentRoot on Apache to point to the public folder and therefore, the url will point to the public folder without it being present in your url.您应该将 Apache 上的 DocumentRoot 更改为指向公用文件夹,因此,该 url 将指向公​​用文件夹,而不会出现在您的 url 中。

Here is an example of a VirtualHost Apache allowing you to listen to the website.loc url and point to the public folder linked to this website (it may not be complete):这是一个 VirtualHost Apache 的示例,它允许您侦听 website.loc url 并指向链接到该网站的公共文件夹(它可能不完整):

<VirtualHost *:80>
    DocumentRoot "/path/to/website/public/" 
    ServerName webiste.loc
    DirectoryIndex index.php

    ErrorLog "/var/log/httpd/error_log"
    CustomLog "/var/log/httpd/access_log" common


    <Directory "/path/to/website/public/">
        AllowOverride none
        Order allow,deny
        Allow from all
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ index.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

If it doesn't work, can you give us the configuration of your VirtualHost on Apache?如果它不起作用,您能否将您的 VirtualHost 在 Apache 上的配置提供给我们? Watch out for sensitive info that may be present.注意可能存在的敏感信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM