Codeigniter Remove index.php from Browser Url - php

I want to create a app url 'http://example.com'. But entering the url, it shows 'HTTP Error 403.14 - Forbidden'. when i have inserted 'index.php' at the last of url like 'http://example.com/index.php' the landing page is rendering in the browser
I have changed the
$config['base_url'] = 'http://example.com';
$config['index_page'] = '';
and
$config['uri_protocol'] = 'REQUEST_URI';
in config.php file. Then i have placed the .htaccess file in the codeigniter root folder along with application and system folder. Then in the .htaccess file i have coded with
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I just want to remove the 'index.php' from the url. I am using IIS 8.5 web server.

htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
my site is working http://demo.crowdfundingscript.com/
config file
$config['uri_protocol'] = 'AUTO';
$config['index_page'] = '';

Replace this line:-
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'AUTO';
also change your base url as below.
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
Write your rules as below:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Hope it will work for you :)

In config.php,
remove index.php in $config['index_page']
For ex :
$config['index_page'] = '';

Related

Remove index.php from url in codeigniter using htaccess

I tried to remove index.php from my url in codeigniter i tried by creating with .htaccess file but it does not works.
RewriteEngine on
RewriteBase /
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
I tried by using this code and also these are mu bse and site url.I not have much knowledge that how to use htaccess properly.Any help is appreciable.
$config['base_url'] = 'http://localhost/xxxx/';
$config['site_url'] = 'http://localhost/xxxx/index.php';
Open config.php and do following replaces
From:
$config['index_page'] = "index.php";
To:
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";
Add in .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Hope this will help you :
Options +FollowSymlinks -Indexes
RewriteEngine on
DirectoryIndex index.php
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and also set your config.php:
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/foldername/';
for more : https://www.codeigniter.com/user_guide/general/urls.html
Try the below code to remove index.php from url, Make an htaccess file in the root folder and paste the below code in it.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
For remove index.php in the url you need to change the configuration.
Change the following in your config.php file
$config['index_page'] = "index.php";
TO
$config['index_page'] = "";
This will remove index.php from url.
If it helps anyone here, this problem drove me crazy and the solution for me was removing the capital letters from the project folder (it was originally localhost/working/CourseIgnite/).
so after many attempts at the problem I changed site to localhost/working/courseignite/
Then using the solutions that everyone posts worked. Mod rewrite on, change base url and index in the config, and used the below in the htaccess.
Just hope this helps as it was driving me bonkers.
RewriteEngine on
RewriteBase /working/courseignite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Then in application/config
$config['index_page'] = "index.php";
TO
$config['index_page'] = "";
and also in application/config
$config['base_url'] = "yourlocalhostip/working/courseignite/";

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'] = '';

CodeIgniter .htaccess Affecting Forms

Removing the index.php from URLs have caused my form pages to not receive POST data.
This form is on the URL http://localhost/guestbook/
The following form tag works:
<form method="post" action="http://localhost/index.php/guestbook/">
This (and leaving it blank) does not work:
<form method="post" action="http://localhost/guestbook/">
The first one does work fine, but it changes the URL the user sees to the action url - I would like to keep the index.php out of the URL.
This is my htaccess.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1/ [L]
How could I get the form to submit to the rewritten URL?
in config file change it
$config['index_page'] = 'index.php';
to this
$config['index_page'] = '';
may be work fine
Try this may help
Htaccess file will be :
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</ifmodule>
And make changes in Confg file application/config.php
Make $config Blank
$config['index_page'] = '';
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Just replace
$config['uri_protocol'] ="AUTO"
to
$config['uri_protocol'] = "REQUEST_URI"
AND IN HTACCESS FILE put 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]

Why does not display controller in Codeigniter?

I have updated Codeigniter from GitHub:
https://github.com/bcit-ci/CodeIgniter/tree/feature/session
In config.php file there is rows:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
File .htaccess:
AddDefaultCharset utf-8
RewriteEngine On
RewriteBase /
DirectoryIndex index.php index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
When I open URL www.site.com I get message:
404 Page Not Found
The page you requested was not found.
Also I tried get controller as like:
index.php/articles/test
Are you running this version on your localhost using xampp?
I got mine working the following way:
$config['index_page'] = '';
and my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site.com/index.php/$1 [L,QSA]

how to remove index.php in .htaccess file in codeiginator

Hi I am a newbie at codeigniter.
When i access the url name "http://abc/php/newseller/home/sign" it is giving 404 error. But when i access http://abc/php/newseller/index.php/home/sign then it will give the page. I want to remove "index.php" and my site should run with this url "http://localhost/php/newseller/home/sign"
For this i tried in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And also remove index.php in application/config/config.php
$config['index_page'] = '';
but getting the same problem of 404
you can try to change also this method in config.php
$config['uri_protocol'] = 'AUTO';
Change the setting in the config.php file
$config['index_page'] = 'index.php';
$config['index_page'] = '';
please remove an index.php file and the set the base URL it will work fine.
please try this htaccess code.
RewriteEngine On
RewriteBase /Project Folder Name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Categories