首页 文章

如何为apache服务器设置codeigniter?

提问于
浏览
1

Updated ,我在Ubuntu服务器上部署codeigniter项目时遇到了一些问题,当我点击链接时出现404 Apache错误 .

当我把项目放在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 .

The error :

未找到

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

Apache / 2.4.18(Ubuntu)服务器位于roy.my-domain.com端口80

这是我的设置:

0 . 检查Apache中的重写mod - 得到“模块重写已经启用”

1 . My project is in /var/www/my-project/

2 . In contains the following : 应用系统public_html index.php .htaccess

  • The .htaccess file :

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

#将所有其他URL重写为index.php / URL RewriteRule ^( . *)$ index.php?url = $ 1 [PT,L]

</ IfModule> <IfModule!mod_rewrite.c> ErrorDocument 404 index.php </ IfModule>

  • The apache2.conf :

<目录/ var / www />选项索引FollowSymLinks需要所有已授予的</ Directory>

<目录/ var / www / html />选项索引FollowSymLinks AllowOverride All需要全部授权</ Directory>

  • The config.php :

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

  • The index.php :

(不要使用../system和../application)$ system_path ='system'; $ application_folder ='application';

  • The controllers :

(codeigniter默认视图)Welcome.php About_Controller.php

  • The views: (codeigniter默认视图)welcome_message.php about.php

本地 - 一切正常......谢谢

3 回答

  • 2

    设置CodeIgniter的简单步骤 .

    • 下载并提取您的域名所在的CodeIgniter public_html或var / www / project .

    • 以URL开启项目:https://example.com/project . 如果您收到欢迎CodeIgniter消息,那么您必须成功安装CodeIgniter .

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

    • 在database.php中>传递您的凭证

    • 在.htaccess中编写代码以从url中删除index.php:

    <IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond%
    ! - f
    RewriteCond%
    !-d
    RewriteRule ^( . *)$ index.php / $ 1 [L]
    </ IfModule>配置

    我认为这将是设置项目的完整过程 . 确保在服务器上启用mod_rewrite . 谢谢

  • 3

    可以通过以下方式触发此错误:

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

    • .htaccess问题

    • mod_security或类似的

    • 在“var / www / my_project”中上传您的项目 .

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

    • 将此代码添加到.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>
    

    并且在你的httpd.conf中 Set AllowOverride to All

    在/ cache文件夹上设置正确的权限,而不是仅仅使文件夹可写,您需要使其可以重复写入 .

    我希望它对你有用 .

  • 1
    <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 .

相关问题