duanlu5055 2017-04-07 09:00
浏览 135

如何为apache服务器设置codeigniter?

Updated, I'm having some issues with deploying codeigniter project on Ubuntu server, i get 404 Apache error when i click on links.

When i put the project in http://roy.my-domain.com/ = /var/www/html/ folder - it's all works fine - but when i added sub directory http://roy.my-domain.com/roy/ = /var/www/html/roy/ - i get 404 errors .

When my url is http://roy.my-domain.com/roy/index.php/about - i get codeigniter 404 error and not apache2.

The error :

Not Found

The requested URL /index.php was not found on this server.

Apache/2.4.18 (Ubuntu) Server at roy.my-domain.com Port 80

Here are my settings :

0 . Checked for rewrite mod in Apache - got "Module rewrite already enabled"

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

2 . In contains the following : application system public_html index.php .htaccess

  1. The .htaccess file :

    < IfModule mod_rewrite.c > RewriteEngine On RewriteBase /html/my-project/ 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 >

  2. The apache2.conf :

    < Directory /var/www/ > Options Indexes FollowSymLinks Require all granted < /Directory >

    < Directory /var/www/html/ > Options Indexes FollowSymLinks AllowOverride All Require all granted < /Directory >

  3. The config.php :

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

  4. The index.php :

    (don't work with ../system and ../application) $system_path = 'system'; $application_folder = 'application';

  5. The controllers :

    (codeigniter default view) Welcome.php About_Controller.php

  6. The views: (codeigniter default view) welcome_message.php about.php

Locally - all works fine...Thanks

  • 写回答

3条回答 默认 最新

  • dream_life5200 2017-04-07 09:21
    关注
    <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]
    

    Try this configuration and don't forget to reload Apache.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线