简体   繁体   English

页面重定向到 404

[英]page redirecting to 404

i have a site called example.com in different languages我有一个名为 example.com 的不同语言的网站

when i call example.com/en - it opens the eng version当我调用 example.com/en - 它打开 eng 版本

if i write example.com/fr - it opens the french version如果我写 example.com/fr - 它会打开法语版本

its a one page project.它是一个一页的项目。 So all is catched in the index.php.所以所有内容都包含在 index.php 中。 i read the url, explode it, and the i get the requested language.我读了 url,展开它,然后我得到了请求的语言。 everything is working fine on localmachine在本地机器上一切正常

on my server, if i call example.com/en - it tries to open a path, that doesnt exist and then i get a 404 error在我的服务器上,如果我调用 example.com/en - 它会尝试打开一条不存在的路径,然后出现 404 错误

what do i have to do so my code works like on the local machine?我必须做什么才能让我的代码像在本地机器上一样工作?

To start debugging your problem, use the Developer menus of your browser... the one that lets you see .network requests."要开始调试您的问题,请使用您浏览器的开发人员菜单……让您看到 .network 请求的菜单。”

With it, you will very quickly be able to see exactly what URL was requested from the server and you'll see the 404 response being returned.有了它,您将很快能够准确地看到从服务器请求的 URL 是什么,并且您将看到返回的404响应。

So, your first check is: *"well, was that the URL that I expected to be requested?"*所以,您的第一个检查是:*“好吧,是我期望被请求的 URL 吗?”*

Then, if it was, check the server-side code to determine why it wasn't able to match that URL.然后,如果是,请检查服务器端代码以确定它无法匹配 URL 的原因。

Remember also that, when your web-browser client requests things like blahblah/fr , that /fr bit is going to be seen (eg by Apache) as a different <Location> .还请记住,当您的网络浏览器客户端请求诸如blahblah/fr之类的内容时,该/fr位将被(例如 Apache)视为不同的<Location> Carefully review the configuration documentation for your web-server of choice to make sure that it knows how to handle the URLs that it will be seeing.仔细查看您选择的 Web 服务器的配置文档,以确保它知道如何处理它将看到的 URL。 (There are several ways to do this so I really can't be more specific since you don't give us any clues as to your server-side setup...) (有几种方法可以做到这一点,所以我真的不能更具体,因为你没有给我们任何关于你的服务器端设置的线索......)

Please add following to the.htaccess:请在.htaccess 中添加以下内容:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Note: If your web host doesn't allow the FollowSymlinks option, try replacing it with Options +SymLinksIfOwnerMatch.注意:如果您的 web 主机不允许 FollowSymlinks 选项,请尝试将其替换为 Options +SymLinksIfOwnerMatch。

This is basically configuration that works with Laravel framework.这基本上是适用于 Laravel 框架的配置。 However, it should work for you as well but you need to set the path properly in the third rewrite rule.但是,它也应该适用于您,但您需要在第三个重写规则中正确设置路径。

The typical trigger for an error 404 message is when website content has been removed or moved to another URL. There are also other reasons why an error message could appear.错误 404 消息的典型触发是当网站内容已被删除或移动到另一个 URL 时。还有其他原因可能会出现错误消息。 These include:这些包括:

  • The URL or its content (such as files or images) was either deleted or moved (without adjusting any internal links accordingly) URL 或其内容(如文件或图像)被删除或移动(没有相应调整任何内部链接)

To solve these problem为了解决这些问题

  • Create an error page ('404.html' or '404.php') in the root directory (if there isn't an existing one already).在根目录中创建一个错误页面(“404.html”或“404.php”)(如果还没有)。
  • Open the .htaccess file (or create one if needed) in the root directory, enter this in 'ErrorDocument 404 /404.html' and save the change.打开根目录中的 .htaccess 文件(或根据需要创建一个),在“ErrorDocument 404 /404.html”中输入此文件并保存更改。 The error page will be generated with this code.将使用此代码生成错误页面。
  • To see if it's worked, try to access an unavailable webpage and hopefully the error 404 message should appear in the browser.要查看它是否有效,请尝试访问一个不可用的网页,希望错误 404 消息应该出现在浏览器中。

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

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