【问题标题】:route codeigniter not working路由codeigniter不工作
【发布时间】:2015-08-19 12:12:03
【问题描述】:

我在 codeigniter 中的路由文件有问题。在 Wamp 上,我的路线运行正常。但是,在我的服务器(共享主机)上,我的路由没有运行。

我的主页在 fr 文件夹中。我的控制器是索引。所以我的默认控制器是'fr/index'。

$route['default_controller'] = 'fr/index';
$route['404_override'] = ''; 

当我写 www.domainName.tld 时,我得到“找不到文件”。没有 CSS 样式。在源代码中我有

1 文件未找到。
2

当我写 www.domainName.tld/aaaa(404 错误)时,我确实遇到了 404 错误:

<!DOCTYPE html>
<html lang="en">
<head>
<title>404 Page Not Found</title>
<style type="text/css">

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

body {
    background-color: #fff;
    margin: 40px;
    font: 13px/20px normal Helvetica, Arial, sans-serif;
    color: #4F5155;
}

a {
    color: #003399;
    background-color: transparent;
    font-weight: normal;
}

h1 {
    color: #444;
    background-color: transparent;
    border-bottom: 1px solid #D0D0D0;
    font-size: 19px;
    font-weight: normal;
    margin: 0 0 14px 0;
    padding: 14px 15px 10px 15px;
}

code {
    font-family: Consolas, Monaco, Courier New, Courier, monospace;
    font-size: 12px;
    background-color: #f9f9f9;
    border: 1px solid #D0D0D0;
    color: #002166;
    display: block;
    margin: 14px 0 14px 0;
    padding: 12px 10px 12px 10px;
}

#container {
    margin: 10px;
    border: 1px solid #D0D0D0;
    -webkit-box-shadow: 0 0 8px #D0D0D0;
}

p {
    margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
    <div id="container">
        <h1>404 Page Not Found</h1>
        <p>The page you requested was not found.</p>    </div>
</body>
</html>

我的 .HTACCESS 运行正常:

Options +FollowSymLinks
RewriteEngine on

#Sub-dir e.g: /cmsms
#RewriteBase /
#
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# Empêche la visualisation de l’arborescence, n’a rien à voir avec le masquage du « index.php ». Options -Indexes 
# Active le module de réécriture d’URL. RewriteEngine on 
# Toutes les URL qui ne correspondent pas à ces masques sont réécrites.
RewriteCond $1 !^(index.php|assets/|robots.txt) 
# Toutes les autres URL vont être redirigées vers le fichier index.php. 
RewriteRule ^(.*)$ index.php/$1 [L]

我认为是托管问题,因为在 wamp 上,我的指令可以正确运行,但不能在我的服务器上运行。

你有什么想法吗?

感谢您的回答。

【问题讨论】:

  • 你检查过你的配置文件的$config['base_url']吗?
  • 是的。我的 base_url 是空的。当我创建链接时,我使用了 base_url (localhost),因为我的文件结构在服务器中。
  • 将您的服务器 url 分配给 base_url 并重试
  • 我也有同样的问题。现在,当我尝试访问我的主页时,我有很多指向 404 错误的链接。始终找不到我的主页的文件 =/
  • 你分配给 base_url 的 url 是什么?

标签: php codeigniter routes shared-hosting


【解决方案1】:

您在哪个版本的 codeigniter 上运行? 如果您在 v3 中,请检查您的控制器和模型的文件名......如果这些文件的起始字母不是大写字母,则重命名它 模型和控制器文件名的首字母必须大写

【讨论】:

  • 感谢您的回答。我不在 v3 中,但我尝试将我的 default_controller 更改为 Welcome。我将welcome.php 重命名为Welcome.php,欢迎类将CI_Controller 扩展为Welcome 类扩展CI_Controller。我也有同样的问题。只是找不到文件。在 wamp 中,它运行正确,但不在我的服务器上。我不明白为什么。
  • 没有。我也有同样的问题。你有什么想法吗?
  • 你能告诉我你的文件结构吗..所以我会有更好的主意,还有配置文件基本 url n 路由代码
  • 现在不可能,但我会向您展示我的文件结构到 3 小时。对不起。
  • 您的网站文件夹中是否有.htaccess??
【解决方案2】:

好的,我有解决方案。这是 htaccess 和路由文件之间的问题。删除您的 htaccess 或对其进行编辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2018-06-27
    相关资源
    最近更新 更多