簡體   English   中英

Symfony 項目僅適用於主頁。 當我導航到其他頁面時,Apache 返回 404

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

一個有 symfony5 的項目。 當我托管到服務器時,我將默認主機路徑從https://example.com更改為https://example.com/public ,因為 index.php 位於 /public 文件夾中。 從那時起,我的網站只能在主頁上運行。 當我導航到其他頁面時,Apache 返回 404。“在此服務器上找不到請求的 URL /bio/”。 一切都在本地主機上運行,​​但不在主機上運行。

您應該將 Apache 上的 DocumentRoot 更改為指向公用文件夾,因此,該 url 將指向公​​用文件夾,而不會出現在您的 url 中。

這是一個 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>

如果它不起作用,您能否將您的 VirtualHost 在 Apache 上的配置提供給我們? 注意可能存在的敏感信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM