XstreamINsanity
XstreamINsanity

Reputation: 4296

.htaccess not acting as suspected

I'm using CI and WAMP on a Windows 7 machine. In my Application folder of the site I have a .htaccess file with the following:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

This was copied and modified CodeIgniter User Guide. And I made sure the rewrite_module (didn't it used to be mod_rewrite?) was active and restarted WAMP. In my controller, I have the following:

<?php

class Forum extends CI_Controller
{
public function index()
{
    $data['title'] = "Card Forums";
    $this->load->view('Header', $data);
    $this->load->model('forumdb');
    $data['sections'] = $this->forumdb->getSections();
    $this->load->view('Home', $data);
    $this->load->view('Footer');
}

public function site()
{
    $data['title'] = "Card Forums - Site";
    $this->load->view('Header', $data);
    $data['section'] = "Site";
    $this->load->view('Forum', $data);
    $this->load->view('Footer');
}
}

When I go to localhost/forum it does exactly as I want. But when I try to go to localhost/forum/site it is displaying the following:


Not Found

The requested URL /forum/site was not found on this server.


In the view Forum I have:

<?php echo $section; ?>

Which is only supposed to display the the variable right now because I want to make sure I'm accessing the page first (just started writing this site Friday). When I try localhost/forum/index.php/site it's giving me a 404 error.

I have a feeling I'm missing something VERY simple here and it's bugging me. Any help would be appreciated.

Upvotes: 1

Views: 165

Answers (2)

Dale
Dale

Reputation: 10469

Here is an updated .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ index.php/$1 [L]

In your /forum/config folder find the config.php and change this line

$config['index_page'] = 'index.php';

To

$config['index_page'] = '';

Then as you mentioned you can use function like base_url('css/site.css');

One thing I generally do with this type of htaccess file is add an entry for a folder called public so in my case it would look like this.

RewriteEngine on
RewriteCond $1 !^(index\.php|public)
RewriteRule ^(.*)$ index.php/$1 [L]

Then I have all my assests in the public folder, and I don't need to keep adding exceptions to my htaccess file.

Upvotes: 2

Seabass
Seabass

Reputation: 1973

For WAMP (and most other environemnts for my CI projects), I've had most luck with the following additional flags in .htaccess:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

Also, Check your uri_protocol in config.php. I've had most luck with setting it to PATH_INFO instead of AUTO.

One last thing to try: CI sometimes detects the base_url wrong in WAMP environments. Either define your base_url in config.php.

Upvotes: 1

Related Questions