CodeIgniter configuration with mod_rewrite, xampp and windows


Question

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.

1
1
12/4/2009 9:55:46 PM

Accepted Answer

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]
5
12/7/2009 5:57:31 AM

If your using XAMPP on a local machine, your should use internal rather than mod_rewrite.

It will load your pages under the alias name.

it took me a while to figure that out - apparently you should use mod_rewrite on remote servers to achieve the same thing.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon