3

I am using this htaccess file on my site to remove index.php.

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

But this file doesn't work.Rewriting is enabled in Apache module.Version of codeigniter used is 2.0.1.

user1163513
  • 4,087
  • 7
  • 24
  • 25

6 Answers6

7

I've tested this without codeigniter, and it works.

I create a folder under htdocs, called "demo". I put ".htaccess" there with your content + additional line (RewriteBase):

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

Then "index.php" below:

<?php
echo $_SERVER['PATH_INFO'];

Tested with: http://localhost/demo/hello

Result: /hello


Things to check:

  • If you put ".htaccess" inside a folder, don't forget to add RewriteBase.
  • Make sure FollowSymLinks is enabled for your directory. See this link for further information.
Muhammad Alvin
  • 1,190
  • 9
  • 9
  • Yes the problem that i was facing was of RewriteBase.Thanks a lot for the solution. – user1163513 Apr 18 '12 at 16:54
  • Hi Muhammad, I have tried this but on my domain somehow this also does not work, I am on hostgator shared hosting, if I am using this then getting 500 error, my other domains are not giving any error, can you please suggest what would be the reason ? – A Bright Worker Mar 09 '13 at 17:27
2

This may quite late solution for Codeigniter 3

Put this on you root folder

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

Go to apache/apache_version/conf/httpd.conf (Im using Laragon)

Put at the end of httpd.conf

Listen 9595
<VirtualHost *:9595>
DocumentRoot "C:\laragon\www\capstone_project"
<Directory "C:\laragon\www\capstone_project">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>

Restart your apache and see if it works.

Mark Anthony Libres
  • 906
  • 1
  • 7
  • 14
1

read this

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Petro Popelyshko
  • 1,353
  • 1
  • 15
  • 38
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

Put This Code into .htaccess file of CI_Folder

 <IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteBase /foldername/ 
    RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /foldername/index.php?/$1 [QSA,L] 
    </IfModule>
    # BEGIN Expire headers <ifModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 5 seconds"
        ExpiresByType image/x-icon "access plus 2592000 seconds"
        ExpiresByType image/jpeg "access plus 2592000 seconds"
        ExpiresByType image/png "access plus 2592000 seconds"
        ExpiresByType image/gif "access plus 2592000 seconds"
        ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
        ExpiresByType text/css "access plus 604800 seconds"
        ExpiresByType text/javascript "access plus 216000 seconds"
        ExpiresByType application/javascript "access plus 216000 seconds"
        ExpiresByType application/x-javascript "access plus 216000 seconds"
        ExpiresByType text/html "access plus 600 seconds"
        ExpiresByType application/xhtml+xml "access plus 600 seconds" </ifModule>
    # END Expire headers

    # BEGIN Cache-Control Headers <ifModule mod_headers.c>
        <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
            Header set Cache-Control "public"
        </filesMatch>
        <filesMatch "\.(css)$">
            Header set Cache-Control "public"
        </filesMatch>
        <filesMatch "\.(js)$">
            Header set Cache-Control "private"
        </filesMatch>
        <filesMatch "\.(x?html?|php)$">
            Header set Cache-Control "private, must-revalidate"
        </filesMatch> </ifModule>
    # END Cache-Control Headers
    # BEGIN GZIP COMPRESSION <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule>
    # END GZIP COMPRESSION
Ak Memon
  • 29
  • 6
  • While this code may answer the question, it would be better to explain how it solves the problem without introducing others and why to use it. Code-only answers are not useful in the long run. – JAL Nov 18 '15 at 02:48
0

Check your Apache site configuration file. On Ubuntu 14.04 the file would be /etc/apache2/sites-available/site.conf

Change lines like this

AllowOverride None

To this

AllowOverride All

Restart Apache to load the updated site.conf

sudo service apache2 restart

This solved it for me.

infinigrove
  • 489
  • 1
  • 7
  • 16