I want to remove index.php from codeigniter url - .htaccess

I want to remove index.php from codeigniter url
my current configurations I tried so far with zero results are
folder structure:
xampp\htdocs\Codeigniter\application\controllers\olx\olx.php
xampp\htdocs\Codeigniter\application\views\olx\frmSignup
my HTACCESS file on the location
xampp\htdocs\Codeigniter.HTACCESS with the following contents nothing else in .HTACCESS file for me
RewriteEngine On
RewriteBase /olx
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
mod_rewrite is enabled checked using phpinfo();
following changes made to config.php file
$config['base_url'] = 'http://mypc/olx';
$config['index_page'] = '';
when try to access this url
http://mypc/codeigniter/olx/frmSignup i get 404 error
changes made to routes.php are
$route['default_controller'] = 'olx';
$route['olx/frmSignup'] = 'olx/frmSignup';
please help I want to access my app without index.php. i am working on localhost with Windows7

Change AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/000-default.conf in ubuntu
Change AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/default.conf in windows
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
....
Then put this code in .htaccess file in root folder in codeigniter
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
It will definately work.

From http://ellislab.com/codeigniter%20/user-guide/general/urls.html - Try
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

after all said by friends, you have to do another thing (I think you are doing it on localhost):
First, double check the suggestions:
then go to windows tray, right click on WAMP icon, and then click on it , go to Apache menu, and then to modules and then check for rewrite_module to see if it is checked or not, and click on it if you find it unchecked (means disabled) to enable it. Now try again and report it...

You just have to create .htaccess file on the root application folder or edit it if you already have. The following .htaccess file works for me.
.htaccess
# BEGIN ci
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<IfModule mod_rewrite.c>
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]
</IfModule>
so not olx as it's a controller and not a folder
in config
$config['base_url'] = '';
$config['index_page'] = '';
in route
$route['default_controller'] = "olx";
and move your
D:\xampp\htdocs\Codeigniter\application\controllers\olx\olx.php
to
D:\xampp\htdocs\Codeigniter\application\controllers\olx.php
and olx should look like
class olx extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
echo "test";
// or $this->load->view('olx/overview.php', $data);
}
}
and try localhost/codeigniter/ or localhost/codeigniter/olx

Related

Two different projects (different index.php's) on same server

I'm trying to run two different php frameworks on the same server. The framework to use is determined by the first path in the uri.
So for example:
http://www.example.com/v1/requestname
will go to the index.php located in:
/var/www/html/api/api
And everything else (http://www.example.com/v2/requestname) will go to the index.php located in:
/var/www/html/api2/public
Here is my apache 2.2 config:
Alias /v1 /var/www/html/api/api
<Directory /var/www/html/api/api>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>
DocumentRoot "/var/www/html/api2/public"
<Directory "/var/www/html/api2/public">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>
I've been attempting to do this with apache, but every request is being routed to api2. Everything I'm looking seems to say this should work.
So here's the solution I came up with for anyone in the future:
Set anything beginning with /v1 to be send to the first version of the API.
Alias /v1 /var/www/html/api/api/index.php
Send everything else to the second version:
DocumentRoot "/var/www/html/api2/public"
<Directory "/var/www/html/api2/public">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>
The trick was adding index.php onto the end of the Alias.

2 codeigniter applications & htaccess

I had a codeigniter proyect working in windows with XAMPP and now I was moving it to my RaspberryPi:
Apache/2.2.22 (Debian)
PHP 5.4.4-14+deb7u5
mysql Ver 14.14 Distrib 5.5.31
I have two codeignitir aplications (principal and panel) with this estructure
/ -> (apache root folder)
/appname/admin
/admin/application/ -> (codeigniter application to panel)
/appname/application/ -> (codeigniter application to public)
Now I can't access to admin controllers and I think is because .htaccess. I get this in some url:
my.domain/appname -> codeigniter welcome for public (this part is empty so I think is OK)
my.domain/appname/admin/login.html -> Not Found. The requested URL /mydomain/admin/login was not found on this server.
my.domain/appname/admin/index.php?controller=admin -> 404 Page Not Found (codeigniter style)
my.domain/appname/admin/hello.html -> hello (a dummy file I put to try, works ok)
In my codeigniter panel proyect I have
$config['base_url'] = 'http://my.domain/myapp/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '.html';
I think it's all about .htaccess but I don't understand them. How many files I need? What folders?
I had this .htaccess in my /appname & /appname/panel before
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /appname #to panel /appname/panel
#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]
#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
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule .* index.php/$0 [PT,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.
ErrorDocument 404 /index.php
</IfModule>
I think RewriteEngine on is activated in my apache2.
I found solution by .htaccess inside admin's folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /appname/admin
#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 'appname' to your applications folder name.
RewriteCond %{REQUEST_URI} ^appname.*
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>
CodeIgniter multiple applications htaccess
<IfModule authz_core_module>
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Cannot remove index.php from CodeIgniter URL

My directory structure is /var/www/CI/ with all the folders viz., application, system under the folder CI. Have created a .htaccess file under CI.
Following is the code in .htacess.
<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]
</IfModule>
Still localhost/CI/blog gives 404 error. Can anyone guide as to where this rule is wrong?
Please try the following
At first, make sure you set the config file like the following..
$config['index_page'] = '';
Also make sure that mod_rewrite is enabled in the httpd.conf file and after that, overwrite your .htaccess file which is located your project root folder not in the application folder with the following code..
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
Make sure in your application/config/config.php file this is set as follows:
$config['index_page'] = '';
Also do this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^CI/(.*)$ CI/index.php/$1 [L]
</IfModule>
Typically you don't put CI in its own directory and put application and system in the root folder.
Check your Apache configuration so that it is allowing an override.
If the AllowOverride is set to None, the rewrite won't work for you.
Adding the following to your httpd.conf (NOT your .htaccess) should fix your problem
<Directory "/">
AllowOverride All
</Directory>
Let me know if it's still not working.
This works. Although, please make sure your mod_rewrite is enabled,
Find the httpd.conf file under the C:\wamp\bin\apache\apache2.4.9\conf folder inside the Apache’s installation folder.
Find the following line #LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf file.You can do this easily by searching the keyword “mod_rewrite”.
Remove the # at the starting of the line, # represents that line is commented.
Then restart the apache server.
You can see now mod_rewrite in the Loaded Module section while doing phpinfo().
Use the following steps,
1. Create .htaccess file in the document root [myroot_folder/.htaccess].
2. open the config file in application/config/config.php and do the following
$config['index_page'] = '';
remove index.php from your base url
if it is $config['base_url']= 'http://localhost/myroot_folder/index.php';
change it to $config['base_url']= 'http://localhost/myroot_folder/';
Now open the .htaccess file and add the following code block
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]
1) Make .htaccess file and put this code.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
2) Change:
$config['index_page'] = '';
remove index.php present in config.php file
3) Rewrite on from your server
If you have not worked all but that you did so, try this:
Change AllowOverride None to AllowOverride All in the virtual host file in /etc/apache2/sites-available/default
Details here

Kohana rewriting urls in .htaccess showing file not found message

I'm using Kohana 3.2 framework, I've put the standard .htaccess file in the same folder of the aplication.
my .htaccess file is
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /mysite/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ /index.php/$0 [PT]
I've tried changing the las line to
RewriteRule ^(.*)$ /index.php/$0
RewriteRule ^(.*)$ /index.php/$0 [PT,L]
RewriteRule ^(.*)$ /index.php/$0 [PT,L,QSA]
RewriteRule .* /index.php/$0 [PT] - [PT,L] - [PT,L,QSA]
But it still shows
Not Found
The requested URL /index.php/login was not found on this server.
The complete path of the app is /var/www/es/ec/mysite
The complete working URL is http://10.0.0.1/ec/mysite/index.php/login
The complete NOT working URL is http://10.0.0.1/ec/mysite/login
Also...
Running in Apache 2.2.3 over CentOS 5
Any idea???
I got it!!
Here is how it gets done when the app is inside other folders.
The complete path of the app is /var/www/es/ec/mysite
The complete working URL is http://10.0.0.1/ec/mysite/index.php/login
The complete NOT working URL was http://10.0.0.1/ec/mysite/login
In /var/www/es/ec/mysite/application/bootstrap.php the Kohana::init stays like this
Kohana::init(array(
'base_url' => '/ec/mysite/',
'index_file' => FALSE,
'charset' => 'ISO-8859-1',
));
And the .htaccess like this
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* /ec/mysite/index.php/$0
Hope this helps some one else!
Cheers!
You can try my Kohana .htaccess file
# Set environment
SetEnv KOHANA_ENV "development"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I use Kohana 3.2, also. This rewrite tends to work for most of my projects.
Let me know how it works out!
In your bootstrap.php inside Kohana::init set 'index_file' => '',

CodeIgniter won't run in a subdirectory

I have a CodeIgniter install running in our root web directory that I copied into a subdirectory called /dev... I edited the config/config.php file to reflect the change so it is now like this:
$config['base_url'] = 'http://mysite.com/dev';
$config['sbase_url'] = 'https://mysite.com/dev';
$config['default_email'] = 'noreply#mysite.com';
$config['site_url'] = 'http://mysite.com/dev';
This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
When I hover over any links on the site they are correct, for example the contact us page link reads www.mysite.com/dev/contact but when I click any of the links I get a 404 error...
Is there something common I am missing?
Enable FollowSymlinks & add a ./ in front of index.php in your RewriteRule:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# block hidden directories
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Also, I would leave blank $config['base_url'] = ''; & use the base_url() url helper when constructing links instead, which makes moving environments easier (e.g. subdir'd dev & root-level production).
... and of course, insure that ModRewrite is enabled in your Apache config.

Resources