Welcome Guest, Not a member yet? Register   Sign In
Ubuntu Codeigniter URL segements not working
#1

[eluser]chuckleberry13[/eluser]
I've just installed apache2 and php5 on ubuntu and things are working great except that I can't get the segmented URLs to work. If I enable the get string I can access different controllers and methods but I would rather not use the GET string. Anybody have any ideas?

This url works: http://127.0.0.2/fastconfig/index.php
This url works: http://127.0.0.2/fastconfig/index.php?c=...getClients (with GET enabled)
This url does not work:http://127.0.0.2/fastconfig/index.php/app/ (note app is the default controller).

I am not getting the Codeigniter 404 but rather the apache 404 page not found error. The apache error log says
Code:
[error] [client 127.0.0.2] File does not exist: /var/www/fastconfig/index.php/app
which means it thinks I am looking for another file / folder named "app" instead of index.php handling this request.


Here is my Virtual Hosts (/etc/apache2/sites-available/default)

Code:
<VirtualHost *:80>
    ServerAdmin webmaster@localhost

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

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Any help would be appreciated.
#2

[eluser]danmontgomery[/eluser]
Try http://127.0.0.2/fastconfig/index.php?/app
#3

[eluser]chuckleberry13[/eluser]
Yeah that works, but I feel like I should be able to do it without invoking the get string using ? ya know.

That might be a decent temp workaround though. Any ideas on what could causing it?
#4

[eluser]idealws[/eluser]
Have you tried adding this to your .htaccess file:

Code:
DirectoryIndex index.php
RewriteEngine on
AddType application/x-shockwave-flash .swf
RewriteCond $1 !^(index\.php|images|css|js|swf|flash|mainvideo|robots\.txt|favicon\.ico|license.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

Then removing the index.php from your config file to look like this?
Code:
$config['index_page'] = '';

Then add the following to your config.php file:
Code:
// $config['base_url']    = '';
$config['base_url'] = "http://".$_SERVER['SERVER_NAME'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

//$config['secure_base_url']    = "http://localhost/local_folder/";
$config['secure_base_url'] = "https://".$_SERVER['SERVER_NAME'];
$config['secure_base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

So your config.php file should look like this at the top:
Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|    http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
// $config['base_url']    = '';
$config['base_url'] = "http://".$_SERVER['SERVER_NAME'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

//$config['secure_base_url']    = "http://localhost/local_folder/";
$config['secure_base_url'] = "https://".$_SERVER['SERVER_NAME'];
$config['secure_base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

This is how I have mine setup and you will be able to access your site as:
http://127.0.0.2/fastconfig/app/

Hope this helps.

Regards,
Ray
#5

[eluser]Unknown[/eluser]
If I remember correctly, mod_rewrite is not enabled by default on Ubuntu's Apache. Check for a symlink to /etc/apache2/mods-available/rewrite.load in /etc/apache2/mods-enabled.
#6

[eluser]n0xie[/eluser]
I assume you are running fastcgi. In that case change your .htaccess to:
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
Notice the question mark in the after index.php...
#7

[eluser]chuckleberry13[/eluser]
I'm not sure what the issue was but after a restart things are working.

Thanks for all the help!
#8

[eluser]Unknown[/eluser]
Thanks Ray. That helped me out. I recently moved from Windows 7 to Ubuntu.




Theme © iAndrew 2016 - Forum software by © MyBB