roberto06
roberto06

Reputation: 3864

CodeIgniter : URL rewriting not working

I have a website created with CodeIgniter, and although the URL Rewriting is working on my local installation (WAMP), it fails on my distant server.

The CI framework is installed in the "/dev" folder.

Here's the error when I try to access a controller using the following URL : http://www.mywebsite.com/dev/controller

Not Found

The requested URL /dev/index.php/controller/ was not found on this server.

I've tried every combination of .htaccess and config.php, but I can't figure out what's wrong.

However, http://www.mywebsite.com/dev/ works just fine.

Here's the .htaccess file :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

And the application/config/config.php file :

$config['base_url']     = '/dev/'; # I tried to put the whole path, didn't work either
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING'; # I tried every possibility, none of them work
$config['url_suffix'] = '';

What's really weird is that this exact configuration used to work on another server, I moved my code today and it doesn't work now...

Any idea ?

Upvotes: 0

Views: 593

Answers (2)

Ijaz Ahmed Bhatti
Ijaz Ahmed Bhatti

Reputation: 729

try it

RewriteEngine On
RewriteBase /your_project_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

and bingo

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143856

You're not using a query string in your rewrite rules, you're using path info. Try changing the uri protocol to:

$config['uri_protocol'] = 'PATH_INFO';

And if that still doesn't work, try changing your rules to append a query string instead:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?$0 [PT,L]
#                       ^------ a "?" here instead of "/"

And make sure the htaccess file is in the dev directory.

Upvotes: 1

Related Questions