user1163513
user1163513

Reputation: 4207

Codeigniter htaccess not working

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.

Upvotes: 3

Views: 22561

Answers (7)

SAM786
SAM786

Reputation: 1

just Change you default Codedigniter-3.1.11 or etc version you have just change the folder name for example:- Codedigniter-3.1.11 to -> Crud_OP and that now can use easily remove index.php file with .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-denter code here
RewriteRule ^(.*)$ index.php/$1 [L]

Upvotes: 0

Mark Anthony Libres
Mark Anthony Libres

Reputation: 1054

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.

Upvotes: 2

infinigrove
infinigrove

Reputation: 489

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.

Upvotes: 0

Ak Memon
Ak Memon

Reputation: 29

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

Upvotes: 0

Kennedy Nyagah
Kennedy Nyagah

Reputation: 3645

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>  

Upvotes: 0

Muhammad Alvin
Muhammad Alvin

Reputation: 1210

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.

Upvotes: 7

Petro Popelyshko
Petro Popelyshko

Reputation: 1379

read this

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

Upvotes: 1

Related Questions