I'm new to CodeIgniter and I'm trying to figure out why the standard methods that I have seen both on the codeigniter site and here on SO aren't working for me to get rid of index.php from the url in my project.
I'm running CentOs, and the path to my project looks like:
/var/www/html/myproject
I have made sure that mod_rewrite is enabled in httpd.conf by checking via phpinfo()
My .htacess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
my config.php looks like this (I have also tried PATH_INFO and REQUEST_URI for uri_protocol):
$config['base_url'] = 'http://localhost/myproject/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
My routes.php looks like this:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['site/price/(.*)'] = "site/price/$1";
The signature for the site controller's price action is this:
public function price($a, $b, $c) {
//code
}
When I go to
http://localhost/myproject/index.php/site/price/32137/2/1
the price function is reached successfully, but when I try
http://localhost/myproject/site/price/32137/2/1
I get an error page saying
The requested URL /myproject/site/price/32137/2/1 was not found on this server.
Am I missing something?
Thanks in advance
EDIT:
If it's any help, I can get to my project's site/index method with just the url: localhost/myproject but none of the other actions appear reachable.
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Use the exact .htaccess mod_rewrite config provided in the docs for Codeigniter
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for me every time.
There are 2 parts to removing index.php from the url:
1) Tell .htaccess to route around index.php. Something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
2) Edit your system/cms/config/config.php configuration file and update this setting from:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Here's a sample .htaccess file I use:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine On
# Keep people out of codeigniter directory and Mercurial data
RedirectMatch 403 ^/(/codeigniter|\.git|\.hg).*$
#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} ^codeigniter.*
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>
ErrorDocument 404 public/index.php
</IfModule>
how about this
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Related
My local xampp codeigniter projec's url was
http://localhost/ci_yudeesh/index.php
But then wanted to remove the index.php part from the url so I followed the steps given in the userguide.
After that i could access the project without index.php with the url
http://localhost/ci_yudeesh/
I have a controller named Home and I can access this using http://localhost/ci_yudeesh/index.php/home
, but when try to access this using http://localhost/ci_yudeesh/home it gives this error:
this is my config:
$config['base_url'] = 'http://localhost/ci_yudeesh/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
this is my .htaccess:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
this is my route:
$route['default_controller'] = 'Home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Can someone help me fixing this? I tried all the other answers to similar type questions but none worked.
Remove the .htaccess from the application folder and put it outside the application folder and written only the below code in it. If it not work then I will give you another .htaccess code.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Change the .htaccess file . Remove the codes from the existing file and add the following codes on the file :-
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteBase /ci_yudeesh/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I am newbie with Codeigniter 1.7.2. I want to skip index.php and method name of Site URL. But I don't know how to skip them.
My site url looks like -
http://localhost/mysadagi_voicetongues/index.php/deal_bazaar/PrivilegeDealsbazaar
So I want skip index.php and PrivilegeDealsbazaar from url.
Please give solution to fix this issue.
Thanks
Use latest version on CI 2.1.3
You can use .htaccess to hide index.php from URL. You can use following .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#AddHandler application/x-httpd-php5 .php
RewriteBase /projectforlder/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
You can not access your controller without specifying it in URL.
you can do this in 3 steps:
1) Create .htacess file in parallel to application holder
and just copy past the following code:
RewriteEngine On
RewriteBase /CodeIgniter/ /* this will be your prj name. Change it as per your directory structure*/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
2) Change $config['index_page'] to blank in config.php in application folder as below:
$config['index_page'] = '';
3) Enable "rewrite_module" of apache.
I forget to tell. open your config file: application/config/config.php and change this line
$config['index_page'] = “index.php”
To
$config['index_page'] = “”
Create a .htaccess file in the root of your app so
system
application
assets
.htaccess
To delete the index.php from your url use this .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
It's not a very good idea to hide the controller name because you will get a lot of problems when routing and linking to other functions.
Hope it helps!
I install codeigniter and start to write some code on it.First i want to remove index.php and make some research about it.I remove it with a small htaccess code below,
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ /pasaj/index.php/$1 [L]
and then set my base_url in config.php as,
$config['base_url'] = 'http://localhost/pasaj/';
and then i decided to use base_url in form's actions
and wrote it like that(please look at action)
<form method="post" id="formSubmit" name="fSubmit" action=<?php base_url(); ?>"kayit/kayitOnay/">
but it did not work
and prints url like that
what i did all is not working
and i suspect from my htaccess file.I removed it. i use it for removing index.php in codeigniter default.
and set my new
base url like that necessarily
http://localhost/pasaj/index.php/
and do not change anything above form code
and it works.
Now, i want to still use this htaccess file in order to remove index.php but when htaccess file exists my base_url works wrongly . What might be the changes in htaccess file ?
try this
RewriteEngine on
RewriteBase /pasaj/
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
My htaccess files on a local server looks like this:
For a Zend Framework web:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
For a CodeIgniter web:
RewriteEngine on
RewriteBase /pasaj/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
This is my standard htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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>
You may need to alter the rewrite base.
To remove index.php from url you can try the following.
Open config.php from system/application/config directory and replace
$config['index_page'] = “index.php” by $config['index_page'] = “”
Create a “.htaccess” file in the root of CodeIgniter directory and add the following lines.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In some case the default setting for uri_protocol does not work properly. To solve this problem just replace
$config['uri_protocol'] = “AUTO” by $config['uri_protocol'] = “REQUEST_URI” from system/application/config/config.php
I tried everything on google related to removing index.php from URL in codeigniter but no solution worked for me
I am using codeigniter version 2.1.0
How I can remove index form my URL ?
Thanks
In application/config.php make sure that
$config['index_page'] = "";
Then set this as your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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>
You're all set!
For me, Raphael Caixetas solution didn't work, but this did :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
i tested this on apache2 on many different hosting and it works great.
use this htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
be sure you have enabled mod_rewirte with a phpinfo();
then do this in config/config.php:
$config['index_page'] = '';
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
if it doesn't works yet, try to change the $config['uri_protocol']='AUTO' to one of the listed inside application/config/config.php file on line 40/54:
sometimes i used : REQUEST_URI instead of AUTO or "QUERY_STRING" for goDaddy hostings
Have you tried using the example given in the CodeIgniter user guide?
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
You can easily remove this file by using a .htaccess file with some
simple rules. Here is an example of such a file, using the "negative"
method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php,
images, and robots.txt is treated as a request for your index.php
file.
http://codeigniter.com/user_guide/general/urls.html
check your httpd.conf file
change
AllowOverride None
to
AllowOverride All
This is what I use and works.
Use this code in your .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php/$0 [PT,L]
Just make sure the .htaccess is in your root folder. (ie: xampp/htdocs)
Then in your config.php(application\config) replace
config['index_page']='index.php'
to
config['index_page']=''.
In addition of the .htaccess file given by Robert Stanley (see his answer), go to application/config/config.php, look for $config['index_page'] = "index.php"; and replace it with $config['index_page'] = "";
Don't forget to change de config file!
application/config.php
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
You just need to create .htaccess file in project folder and write:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And You don't need to define in base_url in config file:
$config['base_url'] = '';// blank it.
I hope it will work perfectly ...
I am an asp.net guy and this is the first time I've dealt with PHP.
Anyhow, I've struggled to migrate an existing site to a new server.
This site is using codeigniter.
When I call http://mydomain/admin
I get a 404 error!
But if I call:
http://mydomain/index.php/admin
it works!
I have placed an .htaccess file on the root:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I have set in the config.php:
$config['index_page'] = '';
My routes.php:
$route['default_controller'] = 'welcome';
$route['scaffolding_trigger'] = '';
I have no idea why it does not work. It must be something very simple I guess...
Thank you!
Did you look through this?:
http://codeigniter.com/wiki/mod_rewrite/
If not, try this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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>
There used to be one from Jamie Rumbelow I used to use a bit, but it's not on his blog anymore... I'm used to nginx now though, so my favorite configuration won't work for you.
Your .htaccess file didn't work for me either. But it worked once I changed the rewrite rule to this :
RewriteRule ^(.*)$ index.php/$1 [L]
I just removed the slash at the beginning.
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
1º - Create an .htaccess file in the root you're CodeIgniter project.
2º - In the created .htaccess file put the code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
try adding RewriteBase / in .htaccess
$default_controller = "home";
$language_alias = array('gr','fr');
$controller_exceptions = array('signup');
$route['default_controller'] = $default_controller;
$route["^(".implode('|', $language_alias).")/(".implode('|', $controller_exceptions).")(.*)"] = '$2';
$route["^(".implode('|', $language_alias).")?/(.*)"] = $default_controller.'/$2';
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
foreach($language_alias as $language)
$route[$language] = $default_controller.'/index';
$route['404_override'] = '';