views:

1147

answers:

3

I'm a noob to CodeIgniter and am trying to figure out the configuration for an app I'm building. Something is wrong with my setup.

I'm running XAMPP on Windows and am using an alias directory to point to the applications directory. In other words: "http://localhost/app_name/ " points to the root directory of the application. It all seems to work well until I do the .htaccess for mod_rewrite. Then every time I try to go to a controller I get pitched back to the xampp root.

My config is:

Directories

/app_root
/app_root/codeigniter // where code igniter is located.
/app_root/main        // where the main app is located.  It' the applications 
                      // directory cut from code igniter and renamed.

.htaccess

<IfModule mod_rewrite.**so**>
RewriteEngine On
RewriteBase **/app_name/**
RewriteCond %{REQUEST_URI} ^codeigniter.*
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>

index.php

$system_folder = "@codeigniter";
$application_folder = "main";

app_name/main/config/config.php

$config['base_url'] = "http://localhost/app_name/";
$config['index_page'] = "";

app_name/main/config/routes.php

$route['default_controller'] = "welcome";

I should also state that the app_name directory is an alias for a different drive than the apache root.

Apache Root: c:\xampp\htdocs\
App_name: d:\projects\app_name\development\

The alias is:

Alias /app_name "d:/projects/app name/development"
<Directory "d:/projects/app name/development">
  Options Indexes FollowSymLinks ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Thanks in advance for the help... And if you don't mind please "explain" what you're doing when you answer with code. I want to know what I'm doing wrong. If you can help me with this I'll buy you a beer (via PayPal). This is frustrating.

A: 
RewriteBase /

in your .htaccess should be

RewriteBase /app_name/

to specify which directory it is..

Thorpe Obazee
That didn't help... Same behavior.
John Swaringen
I changed the mod_rewrite.c to mod_rewrite.so now I get the object not found error message. when I try to go to http://localhost/app_name/welcome/I should also state that the app_name directory is an alias for a different drive than the apache root. Apache Root: c:\xampp\htdocs\App_name: d:\projects\app_name\development\The alias is: Alias /app_name "d:/projects/app name/development"<Directory "d:/projects/app name/development"> Options Indexes FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all</Directory>
John Swaringen
A: 

First, a question. Is your $system_folder variable really set to:

$system_folder = "@codeigniter";

or was that a nerf from the weird (to me) way SO uses markdown? If it is, remove the @. It is an invalid character for directory/file names.

Next, I believe your RewriteBase should be /, since you use an alias in Apache, but don't quote me on that.

I personally use the .htaccess format supplied here: CodeIgniter URLs in the User Guide; under the heading Removing the index.php file. There are many ways to do it, however. A quick Google search yields a couple thousand.

Do you have mod_rewrite enabled? Check the forum post here.

Mike
Thanks Mike, I tried renaming it to "ci" instead, I got the @codeigniter from another tutorial. Still didn't work. I'm thinking it's my machine, so I'm goign to try creating one for my personal website to see if that's the case.
John Swaringen
A: 

Success!!

I finally managed to get URL rewrite working and what a long arduous journey it was. Here is what I got working finally. Take note that there is no backslash on the RewriteBase. Very interesting given what I've read. Thanks to everybody who tried to help.

# Options
Options -Multiviews
Options +FollowSymLinks

#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /app_name

#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

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