PHP Codeigniter - Apache virtual host setup trouble

21,270

Sounds like you're having rewritemod/htaccess issues rather than VirtualHost issues. Have you made sure that you've got a block such as

<VirtualHost *:80>
  ServerName mysite.lo
  <Directory /home/tilman/Sites/mysite>
    AllowOverride All
  </Directory>
</VirtualHost>

somewhere within your config files? The fact that /index.php and /index.php/welcome work, tell me that it's the rewrite mod that's not functioning...

Share:
21,270
Tilman Koester
Author by

Tilman Koester

Updated on July 09, 2022

Comments

  • Tilman Koester
    Tilman Koester almost 2 years

    This has been doing my head in. Hope you guys can help. I can't find out where the error lies.

    httpd-vhosts.conf

    NameVirtualHost 127.0.0.1
    
    <VirtualHost 127.0.0.1>
        DocumentRoot /opt/lampp/htdocs
        ServerName localhost
    </VirtualHost>
    
    <VirtualHost 127.0.0.1>
        DocumentRoot /home/tilman/Sites/mysite/www
        ServerName mysite.lo
    </VirtualHost>
    

    /etc/hosts

    127.0.0.1   localhost
    127.0.0.1   mysite.lo
    

    config.php

    $config['base_url'] = "http://mysite.lo";
    $config['index_page'] = "";
    

    www/.htaccess

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    <IfModule !mod_rewrite.c>
        ErrorDocument 404 index.php
    </IfModule>
    

    Now http://mysite.lo shows me the default controller. http://mysite.lo/index.php as well. So does http://mysite.lo/index.php/welcome.

    But http://mysite.lo/welcome doesn't.

    http://localhost/mysite/www/welcome works as expected.


    edit: I want to move system and application out of the web root. So my file structure looks like this:

    application/
    system/
    www/
     '- index.php
    

    In index.php I changed the paths to system and application folder, of course.