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
Related
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.
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 have my project developed in CodeIgniter which works perfect on XAMPP Server but Not working on WAMP server.
I've changed
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
and .htaccess I've
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Homepage of website appears properly. But no link is working whenever I click on any link wamp server homepage appears in French version.
Project run properly on WAMP only if there is index.php in URL.
e.g.
http://localhost/codeigniter/welcome/view (This link doesn't work)
http://localhost/codeigniter/index.php/welcome/view (Links works properly)
Try this one, it's working everywhere :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
Enable the mod_rewrite in your httpd.conf file
In my case I have installed WAMP on local disk C
to find httpd file just navigate to C:\wamp\bin\apache\apache2.2.6\conf
open httpd.conf file with notepad editor then find the line below:
#LoadModule rewrite_module modules/mod_rewrite.so
and uncomment it
save the file and restart Apache for the new setting to take effect.
try this
RewriteEngine On //missed this
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
check RewriteBase in .htaccess file.
it would be like below
RewriteBase /your project folder name/
copy below code and paste it in your .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /codeigniter/
#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]
#RewriteRule ^page/(.*)$ index.php?/#$1 [R=301,L,NE]
# 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;
hope it will help you. and check one thing i.e your url. if there is any ~ symbol then .htaccess file will be different. otherwise the above code will work. Thanks.
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'] = '';
I'm using the following htaccess script so that I can hide index.php from the URI.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
But I'm facing a major problem :(
I have a directory named assets beside my index.php file and it should be there. When I browse the directory by browser, then Codeigniter’s not found page displays. I can't browse the file /assets/image.jpg but it displays when I call it from an <img> tag
What can I do now?
Note that it is working in my local server (localhost) but not in the live server.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]
That'll pass any request that Apache wouldn't serve off to CodeIgniter. This way you're free to create directories all over without updating your rewrite rules, and you don't need to setup 404 handling in Apache (even inside your image/resource directories).
Credit goes to the Zend Framework authors that recommend this bit in their user guide. This version is slightly modified for CodeIgniter.
This is the .htaccess file I use for my CI install:
If you have it in a subfolder you will need to edit RewriteBase.
<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>
Here is complete solution which i am using and found working nicely:
Place this code snippet below in .htaccess file at your project root like http://localhost/myProject
RewriteEngine On
RewriteBase /appDirName
RewriteCond %{REQUEST_URI} ^appDirName.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And at your CI config file located at system\application\config\config.php
$config['uri_protocol'] = "REQUEST_URI";
# Turn on URL rewriting
RewriteEngine On
# Put your installation directory here:
RewriteBase /
# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the images/, js/, or css/ directories
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|css)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
I use this and it work perfectly!
Insert the following into your .htaccess
# Change "welcome" to your default controller:
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/$ $1 [L,R=301]
# Checks to see if the user is attempting to access a valid file,
# if not send them to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]