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'] = '';
Related
I have already tried all the possible solutions that I've find in SO, but I still unable to load my controllers without adding the index.php/ before (CodeIgniter), I'm not even able to load my default controller as CI throws a 404 error.
I am using CI 2.1.3
My config is as follows:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //tested all the options
My .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>
Thanks for you time.
Kind regards.
Solution for :
" but I still unable to load my controllers without adding the
index.php/ before (CodeIgniter), I'm not even able to load my default
controller as CI throws a 404 error."
Use this .htaccess in your main folder i.e where the application is in.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you are running on Linux Server add this code in your .htacess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
application/config/config.php
$config['index_page'] = 'index.php';
To
$config['index_page'] = '';
I am struggling with this for hours now:
I have a codeigniter application in a sub folder in a godaddy hosting, lets say:
mydomain.com/myfolder/myapp/
I have this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myfolder/myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
</IfModule>
I read this doc: https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips
but it won't help neither. Maybe because my ci app is in a subfolder?
How can I hide the index.php? and make it work with friendly urls?
Create a .htaccess file in you root directory (where codeigniter's index.php is) with this:
<IfModule mod_rewrite.c>
RewriteEngine On
#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 %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Then in your application/config/config.php :
$config['index_page'] = '';
This should solve the issue.
Use the following .htaccess for Godaddy hosting server. Please let us know if it works.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
Have your /myfolder/myapp/.htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myfolder/myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
then in /myfolder/myapp/application/config/config.php you need to have this config:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I'm surprised nobody wrote that you're supposed to put
Options +FollowSymlinks
at the beginning of your .htaccess file, for a GoDaddy hosted website.
htaccess code :
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
config file :
$config['base_url'] = 'http://baseurl/apps';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['enable_hooks'] = FALSE;
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
I am getting "404 page not found " error coming.
when i changed htaccess file
RewriteRule ^(.*)$ index.php?/$1 [L] to RewriteRule ^(.*)$ index.php/$1 [L]
"no input file specifed" error arise.
I have tried several htaccess codes,but still i am getting these issues.
I am using above htaccess codes , for removing index.php from the url.
Try setting
RewriteBase /apps/
in your .htaccess file
In general I use this htaccess, and it never let me down:
<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>
Can't use comments yet, so am using the answer box then. You might want to take a look at this question, which got solved and seems like it's almost exactly the same as your issue: CodeIgniter htaccess and URL rewrite issues
edit: If you're using nginx or another webserver, please bear in mind that .htaccess files are not supported on these servers. I too sometimes get 'file input not specified' errors in nginx with some applications. Mostly it is, because those servers don't support .htaccess files. So, please be sure you're using Apache.
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]
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