0

现在,我的 .htaccess 文件中包含以下内容:

#Redirect 404 errors to homepage (English)
ErrorDocument 404 /

但最近我在我的网站上添加了一些法语内容。它的 url 格式是这样的:domain.com/fr/[article]并且默认的英文内容只是在根domain.com/[article]上。

现在我想让 404 ErrorDocumentErrorDocument 404 /fr/出现在 URL 开头的 /fr/ 中,如上所示。

有谁能够帮助我?

4

1 回答 1

3

如果您使用默认的 php 文件作为错误页面会更容易:

ErrorDocument 404 /error.php

从你那里error.php你有类似的东西:

<?php
$path_parts = pathinfo($_SERVER['REQUEST_URI']);
$parts = explode('/', $path_parts['dirname']);
if (in_array("fr", $parts))
{
    // show French error message
    // or if u want to redirect to the root of that language
    //header("Location: http://domain.com/fr/");
}
else
{
    // show English error message
    // or if u want to redirect to the root of that language
    //header("Location: http://domain.com/");
}
于 2013-09-21T22:09:03.307 回答