如何为apache服务器设置codeigniter?

问题描述:

更新, 我在Ubuntu服务器上部署codeigniter项目时出现了一些问题,当我点击链接时,出现404 Apache错误。如何为apache服务器设置codeigniter?

当我把项目放在http://roy.my-domain.com/ =/var/www/html /文件夹中时,它的工作正常 - 但是当我添加子目录http://roy.my-domain.com/roy/ =/var/www/html/roy /时,我得到了404错误。

当我的网址是http://roy.my-domain.com/roy/index.php/about - 我得到codeigniter 404错误,而不是apache2。

错误:

未找到

请求的URL的index.php在此服务器上找到。

的Apache/2.4.18(Ubuntu的)在roy.my-domain.com端口80

这里服务器是我的设置:

0。在Apache中检查重写mod - 得到“模块重写已启用”

1。 我的项目在/ var/www/my-project/

2。 在包含以下内容: 应用 系统 的public_html 的index.php htaccess的

  1. .htaccess文件:

    < IfModule mod_rewrite.c > RewriteEngine On RewriteBase/html/my-project/ RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}! -d

    #重写所有其他URL的index.php/URL重写规则 ^(。*)$的index.php?URL = $ 1 [PT,L]

    </IfModule>配置 < IfModule!mod_rewrite的.C> 的ErrorDocument 404的index.php </IfModule>配置

  2. Apache2的。CONF:

    <目录/ var/WWW /> 选项指标的FollowSymLinks 要求所有授予 < /目录>

    <目录/ var/www/html等/> 选项指标的FollowSymLinks 的AllowOverride所有 要求全部授予 </Directory>

  3. config.php:

    $ config ['base_url'] ='http://roy.my-domain/my-project/'; $ config ['index_page'] =''; $ config ['uri_protocol'] ='AUTO';

  4. 在index.php:

    $ system_path = '系统'(不../system和../application工作); $ application_folder ='application';

  5. 的控制器:

    (笨默认视图)的welcome.php About_Controller.php

  6. 的观点: (笨默认视图)welcome_message.php about.php

  7. 本地 - 一切正常。 ..Thanks

开始=>
+0

您能否提供Apache错误日志? – Viktor

+0

嗨,感谢 - 从Apache服务器没有错误 - 我无法查看除主页以外的任何页面 - 当点击链接 - 我得到'页面无法显示'错误 – RoyBarOn

+0

Viktor - 我已经设置$ config [' index_page'] ='';现在我得到一个错误 - 我更新我的帖子与错误内容 – RoyBarOn

<Directory /var/www/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
</Directory> 

的.htaccess:

RewriteEngine On 
    RewriteBase /html/project/ 

    RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*) 
    RewriteRule^%1/%2 [R=302,L,NE] 

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC] 
    RewriteRule^/%1/ [L,R=301] 

    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

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

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

试试这个配置,不要忘了重装了Apache。

设置CodeIgniter的一个简单步骤。

  1. 下载并解压你的CodeIgniter public_html或var/www/project你的域指向。
  2. 将您的项目打开为URL:https://example.com/project。如果您获得欢迎CodeIgniter消息,则必须成功安装CodeIgniter。

  3. 确保在您的服务器上启用了mod_rewrite。

  4. 在database.php中>通过您的凭据
  5. 写代码在.htaccess从URL删除的index.php:
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

我认为这将是对整个过程设置项目。确保在服务器上启用mod_rewrite。由于

+0

静态链接无法显示 - 可能在config.php中有错误我将base_url配置为http://mysite.domain.com并将index_page配置为index.php – RoyBarOn

+0

对于base_url ..您必须设置$ confi [' base_url'] =“http://mysite.domain.com”.. \ –

+0

还有一件事...你的链接是否与index.php一起工作 –

这个错误可以通过触发以下几点:

  • 服务器配置错误(httpd.conf文件)

  • 的.htaccess发出

  • 的mod_security或类似

    1. 将你的项目上传到“var/www/my_project” 。

    2. 在配置文件中:
      $config['base_url'] = '';
      $config['index_page'] = '';

    3. 这段代码添加到您的.htaccess文件删除index.php文件,并把这个.htaccess文件在主文件夹。

      <IfModule mod_rewrite.c> 
          RewriteEngine On 
      
          RewriteCond %{REQUEST_FILENAME} !-f 
          RewriteCond %{REQUEST_FILENAME} !-d 
      
          # Rewrite all other URLs to index.php/URL 
          RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
      
          </IfModule> 
          <IfModule !mod_rewrite.c> 
           ErrorDocument 404 index.php 
          </IfModule> 
      

而且Set AllowOverride to All在httpd.conf

设置上/缓存文件夹的正确权限,而不是仅仅使该文件夹可写的,你需要使它禁起来写。

我希望它能为你工作。

+0

Jay Kareliya - 谢谢 - 但现在我无法访问该网站 - 当我去http://my_site.my_domain.com/my_project - 它的重定向我到www.my_site.my_domain.com/my_project - 任何想法为什么? – RoyBarOn