Removing index.php in Codeigniter 3 apache2 server - php

I am working on Code Igniter in Kali Linux, I have configured .htaccess file as mentioned in Documentation and configured file correctly but its not working without index.php
a2enmod rewrite
I have also enabled rewrite mode and restarted apache. Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

in config.php
$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';
create .htaccess file with the following at your project's loctation
(for eg: /var/www/html/yourproject create .htaccess inside 'yourproject' folder )
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
add the below to your virtual host configuration file
<Directory "/var/www/html/yourproject">
Options All
AllowOverride All
Allow from all
</Directorey>
then restart apache

Follow this steps to remove index.php from url
1)Remove "index.php" from config.php file
$config['index_page'] = "";
2) Your .htaccess file should be:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
3)Some cases you also have to change this in config file
//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"

Simply use this in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Related

Codeigniter3 can't remove index.php on xampp

I know there's so many topic about this, but I've tried and that isn't work.
my ci is located at htdocs/codeigniter3
I saw .htaccess inside of codeigniter3/application folder, but I leave it alone. I create new .htaccess on root folder codeigniter3 (outside of application)
my .htaccess is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
also on config.php:
$config['base_url'] = 'http://localhost/codeigniter3/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
on httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
this mod_rewrite.so file also avaiable on apache/modules
Try this in your .htaccess file
RewriteEngine On
RewriteBase /YOUR_PROJECT_NAME
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Edit your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
it work both local and live form me

Codeigniter website not working on live server page not found

I have uploaded my website on 000webhost server in vegshop folder, my link is "http://sp16bcs034.000webhostapp.com/vegshop/", however there is error 404 page not found
and my .htaccess file code is:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1
!^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Try the following
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
In some cases the default setting for uri_protocol does not work properly. Just replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess code vary depending on hosting server. In some hosting server need to use an extra ? in the last line of above code. The following line will be replaced with last line in applicable case:
// Replace last .htaccess line with this line
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Try this htaccess file, you have uploaded code in the subfolder.
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^$ /vegshop/index.php [L]
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /vegshop/index.php/$1 [L,QSA]
Or sometimes time you have to replace the last line in above code with this as per server
RewriteRule ^(.*)$ /vegshop/index.php?/$1 [L,QSA]
Place below .htaccess file in vegshop folder
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /vegshop
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<ifmodule !mod_rewrite.c>
ErrorDocument 404 /index.php
</ifmodule>
In application/config/config.php set as below
$config['base_url'] = 'http://sp16bcs034.000webhostapp.com/vegshop/';

Removing index.php from CodeIgniter URL

I'm struggling with removing the 'index.php' part of my CodeIgniter URL.
I'm using CodeIgniter version 3.1.2. I've followed all steps on other questions about this:
Changed $config['index_page'] = 'index.php' to $config['index_page'] = ''
Changed $config['uri_protocol'] = 'AUTO' to $config['uri_protocol'] = 'REQUEST_URI'
Added a .htaccess file in the root folder of my project with the following code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
However when I try to access my site, I get the following error code.
Not Found
The requested URL /Toneel/Site/index was not found on this server.
The rewrite module is turned on in my Apache Server.
Can anyone help me out with this issue?
This setting worked for me.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
To allow overriding htaccess in Apache Configuration you have to edit and change /apache2.conf file to
AllowOverride All
And restart server.
Try this code in .htaacess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Try this in your .htaccess file
RewriteEngine On
RewriteBase /yourfolderhere/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In my case, it works with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project-name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
** Important, this should be in an .htaccess file in the root of your project.
In config should be like this:
$config['base_url'] = 'http://your-url-here/';
$config['index_page'] = '';

Index.php remove from url is not working in CI 3

I have tried a lot to remove index.php from the url .
Its not working at all.
In config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Then put this below code in .htaccess of my project root.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
I have tried ,its throwing page not found errors only.
Any suggestion ??
Thank you
Your base URL is not the base domain name, so modify your .htaccess file and add the following:
RewriteBase /cloud
This should fix your issues.
You need to change config.php and .htaccess file.
Changes in application/config/config.php
$config['index_page'] = ""; // And Remove index.php
Changes in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Make Sure
Your .htaccess must under cloud directory.
Rewrite module must be enabled in Apache.
try this ,
Changes in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Make sure your RewriteEngine is on in apache conf file if not then follow this link
How to enable mod_rewrite for Apache 2.2

How to skip index.php in URL rewriting?

I have set WAMP up and running without too much hassle. But thing is I could not skip past index.php in my URL (localhost/index.php/login is working but localhost/login is not working).
Anyway my project is based on CI framework and I was using vagrant previously for hosting same project and which is working perfectly for this case. I have checked that the rewrite_module on for Apache and here it is my .htaccess file.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Please help me out from here.
First of all go in your project myproject-application->config.php
replace line no. 29
From
$config['index_page'] = 'index.php';
To
$config['index_page'] = '';
Then add .htaccess file on your root folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Try this .htaccess file code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Categories