Codeigniter controller in subdirectory not working in virtual host

1.5k Views Asked by At

I need help with CodeIgniter -- trying to it to work in virtual host envirnoment in Ampps.

I have been following the following tutorial: http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/

I am trying to have two installations of CodeIgniter running in two directories: /students and /teachers

www.test.com -> goes to /teachers directory

www.user1.test.com -> goes to /students directory

I have the above working on my local machine. The different URL's take me to the correct directory. CI works. Problem arises when I try to access controller using redirect.

if I try to redirect('error') I get:

user2.test.com/user2.test.com/error

Also get an "internal server error"

if I type in

user2.test.com/error

I get an "internal server error"

if I type in

user2.test.com/index.php/error

I get desired result

It works if I try to load view directly in

$this->load->view('error')

I think I need help with the urls and paths. Any guidance most gratefully received.


Nothing particularly enlightening in CI log files

In Apache logs I find: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Things I have changed:


htaccess in root - changed rewrite base. Also takes out index.php

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /students/

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*

RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>

 ErrorDocument 404 index.php

</IfModule>

application/config.php

$config['base_url'] = $_SERVER['HTTP_HOST'];

As per tutorial. Needs to be dynamic.


my Apache hppd-vhosts.conf file

NameVirtualHost 127.0.0.1:80
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "C:/Program Files/Ampps/www/teachers"
    ServerName test.com
    ServerAlias test.com

    <Directory "C:/Program Files/Ampps/www/teachers">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Program Files/Ampps/www/students"
    ServerName test.com
    ServerAlias *.test.com

    <Directory "C:/Program Files/Ampps/www/students">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

index.php in root

kept as is. Things got worse when I tried to change these

$system_path = 'system';
$application_folder = 'application';
1

There are 1 best solutions below

0
On

what about your host file? your host file should be 127.0.0.1 test.com and first try to disable the student sub domain and see if it dose work. Its look like your both ServerName test.com is same try to change the other one with student.com and see whats happen most probably both are conflicting