【问题标题】:Codeigniter: from localhost to webserverCodeigniter:从本地主机到网络服务器
【发布时间】:2017-07-30 05:40:15
【问题描述】:

大家好。我拼命地试图让 codeigniter 在网络服务器上运行。启用了 apache mod_rewrite,我尝试了几乎所有在互联网上找到的相关内容,但没有任何效果。

网络服务器上的目录是

cgi-bin 文件夹已经存在。我读过的帖子说,cgi-bin 文件夹与it is hardly used these days 无关。 但这是第一个问题:这也适合我吗?我应该使用哪个 .htaccess 文件?为什么要放一个 .htaccess 文件?

它们似乎都不起作用: 我尝试了几种设置,最终得到了两个 .htaccess 文件的以下版本:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test94252.test-account.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test94252.test-account.com/index.htm [L]
</IfModule>

我的目标很简单,如果我调用域http://website.com/,则调用 /website/application/views/index.php。 这个 .htaccess 文件有什么问题?

编辑:在我的本地机器上,我通过 http://localhost/website/Controller/Function 调用该 index.php 文件。

请注意:为了测试,我将 index.htm 放入 /website/ 以检查重定向是否完成,但它不起作用。

我期待收到您的来信。

【问题讨论】:

  • 您好,“网站”文件夹是否位于 public_html 文件夹中?

标签: php apache codeigniter mod-rewrite web


【解决方案1】:

第一:

不,您应该安全删除它。 cgi-bin 历史上是唯一可以存储可执行或脚本代码(二进制文件、shell 脚本等)的地方。它主要是一个历史遗迹,因为大多数主机允许从任何地方执行脚本。

当 .htaccess 文件被放置在一个“通过 Apache Web 服务器加载”的目录中时,Apache Web 服务器软件会检测并执行 .htaccess 文件。 .htaccess可以是内容密码保护,也可以是图片防盗链。

第二个:

您应该在./website 文件夹中编辑.htaccess

还有:

我的文件.htaccess 在服务器中运行如下:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>

更新:

让我们用另一种方法再试一次。

  1. application/config.php 文件中进行以下更改

    $config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';
    
  2. 使用下面的代码在你的根目录中创建.htaccess 文件

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

注意:删除&lt;IfModule mod_rewrite.c&gt;&lt;/IfModule&gt;

【讨论】:

  • 谢谢 vanloc,所以如果我理解这个权利,我可以使用任何 .htaccess 文件,因为它的位置无关紧要。但它仍然无法正常工作。当我查看您的文件时,它与codeigniter.com/userguide3/general/urls.html 部分相似。但我不明白我将如何快速告诉在哪里可以找到 /application/views/index.php
  • 它指向/index.htm,就像没有任何.htaccess文件一样
  • 感谢您的努力。我检查并更新了配置中的所有值并删除了标签 。但仍然没有效果,这意味着 /index.htm 已加载。
  • 尝试签入application/config/routes.php。请将您的 $route['default_controller']application/config/config.php 的值发布到:$config['base_url']
  • $route['default_controller'] = 'pages/view';到目前为止,我从未想过 default_controller。
猜你喜欢
  • 2013-01-24
  • 2013-09-17
  • 2016-01-09
  • 2019-07-15
  • 1970-01-01
  • 2011-11-03
  • 2016-02-11
  • 2017-02-02
  • 2015-10-11
相关资源
最近更新 更多