简体   繁体   English

在此服务器上找不到请求的 URL

[英]The requested URL was not found on this server

While hosting a codeigniter website on my server, the first page is coming through fine and the other links are showing an error as shown below.在我的服务器上托管 codeigniter 网站时,第一页正常,其他链接显示错误,如下所示。

Not Found未找到

The requested URL /site/ourservices was not found on this server.在此服务器上找不到请求的 URL /site/ourservices。

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

How to sort this out?如何解决这个问题? I am a beginner.我是初学者。

Add these lines to .htaccess : (based on codeigniter urls docs )将这些行添加到.htaccess : (基于codeigniter urls docs )

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

i will help to you .. i have faced this problem few days ago .. try to include below code in your .htaccess file.我会帮助你..几天前我遇到了这个问题..尝试在你的.htaccess文件中包含以下代码。

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
ErrorDocument 404 index.php

Add these lines in your .htaccess (your project root directory):在您的 .htaccess(您的项目根目录)中添加这些行:

RewriteEngine On
RewriteBase /yoursite

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Do you have a Site.php Controller in your /application/controllers folder?您的/application/controllers文件夹中有Site.php控制器吗?

Or, do you have a route that points to an existing Controller/function?或者,您是否有指向现有控制器/功能的路由?

Follow either of the following two methods:请遵循以下两种方法之一:

  1. Create a Controller, and name is /application/controller/Site.php .创建一个控制器,名称为/application/controller/Site.php You can copy the Welcome.php Controller for quick file creation.您可以复制Welcome.php控制器以快速创建文件。 Then change the name of the Class to Site instead of Welcome .然后将类的名称更改为Site而不是Welcome Now, add a function in there and name it public function ourservices()现在,在其中添加一个函数并将其命名为public function ourservices()

-or- -或-

  1. Go to your /application/config/routes.php file and add a route in there that checks "site/ourservices" and point it to some function in an existing controller.转到您的/application/config/routes.php文件并在其中添加一个检查“站点/我们的服务”的路由,并将其指向现有控制器中的某个功能。 ie $route['site/ourservices'] = 'Welcome/ourservices';$route['site/ourservices'] = 'Welcome/ourservices'; , as long as you have function called public function ourservices() in your /application/controllers/Welcome.php controller. ,只要您的/application/controllers/Welcome.php控制器中有名为public function ourservices()

In the newly created function in your controller, call the appropriate view: $this->load->view('location/of/view/file') which would try to load an existing file /application/views/location/of/view/file.php .在控制器中新创建的函数中,调用适当的视图: $this->load->view('location/of/view/file')它将尝试加载现有文件/application/views/location/of/view/file.php Make sure this file exists.确保此文件存在。

Open "000-default.config" in editor, file available in "/etc/apache2/sites-available/000-default.conf" and change "AllowOverride" from "None" to "All":在编辑器中打开“000-default.config”,文件在“/etc/apache2/sites-available/000-default.conf”中,并将“AllowOverride”从“None”更改为“All”:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Then save and restart your Apache server .然后保存并重新启动您的 Apache 服务器 If after doing this not opening your page then check if your Apache rewrite module is enabled or not.如果这样做后没有打开您的页面,请检查您的 Apache 重写模块是否已启用。 If not enabled then run this command in terminal如果未启用,则在终端中运行此命令

  1. sudo a2enmod rewrite
  2. sudo service apache2 restart

then check your page.然后检查您的页面。

Then save and restart your Apache server.然后保存并重新启动 Apache 服务器。 If after doing this not opening your page then check if your Apache rewrite module is enabled or not.如果这样做后没有打开您的页面,请检查您的 Apache 重写模块是否已启用。 If not enabled then run this command in terminal如果未启用,则在终端中运行此命令

While hosting a codeigniter website on my server, the first page is coming through fine and the other links are showing an error as shown below.当在我的服务器上托管一个Codeigniter网站时,首页显示正常,其他链接显示错误,如下所示。

Not Found未找到

The requested URL /site/ourservices was not found on this server.在此服务器上找不到请求的URL / site / ourservices。

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。

How to sort this out?如何解决呢? I am a beginner.我是初学者。

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

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