views:

552

answers:

4

how to remove index.php from my url in codeigniter . i remove index.php from my config file and i have run my rewrite_module in apache(2.2.11) and my .htaccess file is

RewriteEngine on

RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

now whenever i click any link it show that request url don't found . so please tell me what is the problem ?

A: 

First of all, make sure that you have defined a default controller. Then make sure that you construct urls in such way that there is a controller associated with them; for example,

Homepage:

example.com/home/

Or for about us page:

example.com/about/  

Also double check that you have turned on mod-rewrite module.

Sarfraz
thanks ahmed , yes i have defined my default controller my home page in route.php $route['default_controller'] = "welcome"; and my config.php $config['base_url'] = "http://localhost/codeigniter2/";
Mehdy
+2  A: 

Try this out in your .htaccess file: The comments should get help get it tweaked in for you.. This works perfectly for me in several CI website installations. Also if mod_rewrite is not installed it will send you to a 404 (or you can change that to suite your purpose)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #'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|(.*)\.swf|images|robots\.txt|css|docs|cache)
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 /application/errors/404.php
</IfModule>

EDIT: Check your virtual hosts file and see if you have these items set--these may allow your htaccess file to rewrite the url correctly:

Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
angryCodeMonkey
thank you shane , i have tried this before from http://codeigniter.com/wiki/mod_rewrite/">http://codeigniter.com/wiki/mod_rewrite/ but its not working .
Mehdy
I just extended the answer, please have a look and see if that helps.
angryCodeMonkey
thanks shane , i have set this in my http.conf file its looks like <Directory /> Options FollowSymLinks AllowOverride all Order deny,allow Deny from all</Directory> but its not working
Mehdy
From what I can tell this should be working. My next suggestion would be for you to create a new virtual host, with a very simple structure (not even CodeIgniter probably) and test out some .htaccess rules to make sure it is even working correctly. If that works then install a fresh CI and get it working there. Too many variables and moving parts in your system may be making it hard to diagnose the issue.. Simple is always better when debugging. :)
angryCodeMonkey
A: 

I also had this problem and found that Shanes answe helped me out. I have my sites setup in WAMP.

RewriteBase /mysite/

the mysite is the alias as set in Apache. Well this worked for all my sites.

A: 

I also had a problem with the rewrite rule suggested in the CodeIgniter user guide. I solved it by removing the slash from in front of index.php

RewriteRule ^(.*)$ index.php/$1 [L]
Stephen Curran