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'] = '';
Related
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/";
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>
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
Can someone tell me why this code would work on my local server but not on godaddy server?
I get the following error on godaddy...
I have creating one codeigniter project and host on godaddy server but .htaccess file does not working
my problem is "https://www.tripbrip.com/index.php/home/app_view" this same url come in my url side but i want to remove index.php in this link
my directory structure is this:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php/?$1 [NC,L]
my config file:
$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
This file run in my localhost but not working on server.
I have use many code but still problem remain same .
If I browse to http://example.com/bootstrap.php I get a 404 resource not available at /
Maybe u can try put this on your .htaccess
<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$1 [PT,L]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And for your config file. maybe u can just empty it.
$config['base_url'] = '';
If still error, you can try this
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
The following setting works fine for me.
RewriteEngine on -MultiViews
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
in application => config => config.php
$config['index_page'] = ''; // should be blank
instead of
$config['index_page'] = 'index.php';
My .htaccess file is:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt|img/|css/|js)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
It removes index.php from the URL and forces a redirect from example.net to www.example.net, but when I enter http://example.net, it does not redirect to www.example.net. How can solve this?
In .htaccess file Change this
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
To
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and in config file made 2 changes:
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/CiFolderName';
$config['index_page'] = '';
set your htaccess
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
remove index.php in your config
$config['index_page'] = '';
Also allow overriding htaccess in your apache
nano /etc/apache2/sites-available/default
and change
AllowOverride All
and restart apache
Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)
And Add the following rules to .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then find the following line in your application/config/config.php file
$config['index_page'] = 'index.php';
Set the variable empty as below.
$config['index_page'] = '';
That's it, it worked for me.
If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one
$config['uri_protocol'] = 'AUTO';