【问题标题】:request not found in codeigniter在 codeigniter 中找不到请求
【发布时间】:2018-08-29 00:14:33
【问题描述】:

我正在使用 codeigniter 开发一个 Web 应用程序。

我有问题

当我这样请求控制器时

http://localhost:8080/Saffron/Product/137/test-text

一切都很好,但是当我这样请求控制器时

http://localhost:8080/Saffron/Product/137/مهارت-های-آموزشی-در مطالعه

收到此错误

The requested URL /Saffron/Product/137/کتاب-غلبه-بر-اضطراب-در-محیط-های-آموزشی was not found on this server.

我使用这个 htaccess 规则

Options -Indexes -MultiViews +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Saffron/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php? [L]
</IfModule>

它在服务器上工作没有错误我在 wamp locahost 上遇到这个问题。问题出在哪里?

更新:

我终于找到了:

重写引擎开启
RewriteBase /Saffron/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
重写规则。 /Saffron/index.php [L]

工作正常

【问题讨论】:

  • 你需要encode-decode你的网址
  • 这是一个“经典”的网络服务器 404 错误,还是你的 Laravel 系统本身发出的错误?您是否在创建/输出此 URL 的任何位置应用了正确的 URL 编码,还是将其留给了浏览器?
  • 它在服务器上工作。我在本地 wamp 上有这个问题

标签: php .htaccess codeigniter wamp


【解决方案1】:

转到您的配置 替换 $config['base_url'] = '';在下面的代码中它将如何帮助您

if( (php_sapi_name() == 'cli') or defined('STDIN') )
{
    $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
    $config['base_url'] .= "://". (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '127.0.0.1');
}
else
{
    $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
    $config['base_url'] .= "://". (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '127.0.0.1');
    $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
}

$config['secure_base_url'] = ((isset($_SERVER['SERVER_NAME'])) ? "https://".$_SERVER['SERVER_NAME'] : '');
$config['secure_base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

对于htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folder name of your webapp/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

【讨论】:

  • 我对 index.php 没有任何问题。我说我的代码在服务器上运行良好,没有错误。为什么我在 localhost 中出现错误。我认为我的 htaccess 无法处理波斯字符
【解决方案2】:

您可以在路由器文件application/config/routes.php 中添加类似的内容。

$route['Product/(:num)/(:any)] = 'Product/$1/$2';

我假设 Saffron 是您的 base_url 目录。

查看下方了解更多信息:

CI URI Route documentation

【讨论】:

    猜你喜欢
    • 2017-05-01
    • 1970-01-01
    • 2012-08-18
    • 2017-06-22
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多