Not Able to remove "Index.php" from URL in codeigniter - php

I am new in codeigniter and i am trying to remove index.php from URL in Codeigniter but not able to do this.
I wrote code in my .htaccess file-
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My Apache mod_rewrite is enable.
But still got 404 error when i am trying to access any controller without using index.php.
Please help.
Thanks.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>
Is the code I'm using, it works on every hosting platform I've used it on.

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

check this code of htaccess file.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
you can find your answer refference here
My .htaccess file is not working
moreover can you share your base url with us? as this error may be due to wrong baseurl set.

Related

I have problems with my codeigniter webapp it works fine on my local host but not on live server

Can any one help me?
I code a web app in php with codeigniter
it works well on my localhost but when I upload it on live server it loads only home page. For other pages it gives a error
''No input file specificed''
When I do google about it.
There are many tricks like change .htaccess but no one works.
What should I do
Check this
It loads foodpark.tk
But does not load
Foodpark.tk/category/index
And all the other pages
this is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Options -Indexes
i also tried to put a question mark after index.php in .htaccess but it gives 404 error from hosting
Sorry for my poor english
Try this in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Try this.
In your .htaccess file Change
RewriteRule ^(.*)$ index.php/$1 [L]
To
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Try below code in .htaccess. This is from my working project. Hope you are using godaddy server.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

.htaccess file not working properly in the sever

I'm developing a web site using Codeigniter 3.X. my issue is that it works fine in localhost. now i uploaded the same to my server but it shows some error like "The page you requested was not found."
my htaccess file looks like this:
RewriteEngine On
RewriteBase /fold1/mainfold/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon.ico|images|smileys|js|assets|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /fold1/mainfold/index.php?/$1 [L]
what is issue with this code ? please help me...
Check the flowing:
Does the paths exist on your server?
Is mod_rewrite enabled on your Apache?
This code for hiding the index.php file .
And for Controller and method better to use route.php file.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I found the reason behind the issue. am using codeigniter3.X .Its file naming rules says that controller and model name should be starts with capital letter. i renamed my controller and model files. now the issue is resolved.
try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

.htaccess file doesn't work properly with path_info and/or get method

Fixed it. Did a small change on the file. It can be seen below.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1 [NC,QSA,L]
I have been trying for a whole day to fix an issue I'm having. I have this .htaccess file which simply rewrites the urls just like
http://example.com/about/?req=true
http://example.com/index.php/about/?req=true
It works on my localhost without a problem, but when I upload it to the server I get this "no input file specified" error. You can see the content of the .htaccess file below.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php/$1 [L]
I tried different things I found on the internet including adding a php.ini file which sets cgi.fix_pathinfo to 1, but none of them worked except one and that one doesn't read the request string. You can see that one below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /index.php?x=$1 [L]
Thanks in advance.
First off all check whether rewrite module is enable in apache or not
if enable then u can use this code hide index.php with in url
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /base_directory_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /base_directory_name/index.php [L]
</IfModule>
I think this will help u .

htaccess - using codeigniter framework

I search a lot websites and lots of links and i follow the same for enable htacces in wamp but facing the problem and now as default use index.php even when i run the page without index.php its not working even msg comes page not found on server i already enable in apache module also the httpd.conf file remove the # sign from rewrite module and i use the mention below code in htaccess file for codeigniter for suggestions i share htaccess code
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
please suggest so i can solve this issue on wamp server
Try this code in your htaccess :
RewriteEngine On
RewriteBase /my_project_name/
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
Try this
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]

apache htaccess codeigniter query string to path

i'm trying to make a codeigniter based website be able to convert index.php?option=test&controller=con1 to /test/con1 using .htaccess i tried multiple examples i found and none seem to work, it goes straight to the home page. any ideas?
i've tried things like
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^\/(.+?)\/(.+?)\/? /index.php/$1/$2 [L]
but doesn't throw any errors or anything.
my current htacces is
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|img|js|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
try put this .htaccess in same directory with your index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Categories