0

I am using snow leopard and I have my local environment and I am trying to get rid of the index.php in the url...here is what i have

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

My config file has this

$config['index_page'] = "";

But when i visit the page without index.php it doesnt work

this works

http://localhost/ci_example/index.php/site

this doesnt

http://localhost/ci_example/site

I tried to follow this

maybe i need to do something with my local conf file...but i really dont know what and i have no idea how to restart apache command line...any ideas

Community
  • 1
  • 1
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

5 Answers5

4

What do you mean when you say "it doesn't work"? Do you get an error? A white screen? A 500 error?

Did you make sure your httpd.conf file has the AllowOverride setting set to All? If not, it may not be using your .htaccess file, meaning the rewrite rules won't be used.

Sarah
  • 513
  • 4
  • 11
  • its a white screen but how do i know what conf file i am using – Matt Elhotiby Dec 23 '10 at 01:26
  • and how do i restart apache on macosx – Matt Elhotiby Dec 23 '10 at 01:27
  • A white screen is usually due to a fatal error in the code along with error reporting being turned off...therefore, it's just a white screen. The conf file is usually located in /conf/httpd.conf where is the installation path for apache. As for restarting apache, it depends on how you installed it. If you installed it using a binary package then there may be a control panel to use to restart it (and also edit the conf file). Otherwise you may need to go into the Services (that's what it's called in Windows) and explicitly restart apache. – Sarah Dec 23 '10 at 01:40
1

Try this .htaccess code & change the base path , it will work for all godaddy and other hostnigs.


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 /winscore

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]


Community
  • 1
  • 1
0

Copy this into your .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CI_FOLDER/
#CI_FOLDER is the Location of your CI files.

#Removes access to the 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]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
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.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>  
Kennedy Nyaga
  • 3,455
  • 1
  • 26
  • 25
0

Try to add RewriteBase in the .htaccess file

RewriteEngine On
RewriteBase /ci_example
Tee Wu
  • 569
  • 2
  • 9
0

Here is something that works for me on OS X.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

The above should work for you without any modification. If you're hosting in a folder lets say like http://myserver.com/my_app/ then change /index.php to /my_app/index.php in both places.

Be sure to go into config.php and change url_protocol to PATH_INFO.

Shivaas
  • 694
  • 3
  • 12