Remove index.php in codeigniter - php

I know it is the most repetitive question of CI.
I am using Kubuntu and have made following changes
$config['base_url']='http://localhost/cii/';
$config['index_page'] = '';
$config['uri_protocol']= 'REQUEST_URI';
I've kept my .htaccess file where index.php is kept (in the root folder) but am getting following error:
The requested URL /cii/welcome/second was not found on this server.(404 error)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Possibly the problem is due to the AllowOverride None of document root path in apache sites-available configuration file. You need to modify the line containing AllowOverride None to read AllowOverride All in the file (/etc/apache2/sites-available/default) to make .htaccess files work as expected. Do restart apache once after made the changes.
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Enabling use of Apache htaccess files.

I would guess that the error is because your CI is located at the subfolder /cii but the rewrite rules point to the root folder.
Try adding RewriteBase /cii/ inside the first block.

Related

Ubuntu Apache gives 404 error but index.php shows site css

I am setting up an application on my ubuntu 18.04 localhost in a sub directory so the url looks like this: localhost/app-name.
The problem is that I keep getting an apache 404 error. I feel like I have tried everything between my default.conf and .htaccess. On the bright side if I type /index.php it atleast gives me a 404 page error from the site itself the site css. Here is my default.conf and .htaccess
FOr what it's worth it was written on litten framework
DocumentRoot /var/www/html/app-name/
<Directory /var/www/html>
AllowOverride All
</Directory>
<Directory /var/www/html/eduTrac-SIS/>
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
RewriteBase /app-name
AllowOverride All
Order allow,deny
allow from all
</Directory>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /var/www/html/app-name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
So I figure it out. I too out all of the extras from the default.conf and let the .htaccess do it's thing along with some other changes within the framework. It all worked out.

Remove index.php in CodeIgniter_2.1.4

I am newbie in Codeigniter and trying to configure Codeigniter.
But i am unable to remove the index.php from url..
I changed the .htaccess file by following data which was given in userguide..
.htacess file contains
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and also changed the config file
$config['index_page'] = '';
when i try to use the following url it results
The requested URL /codeigniter/pages/view was not found on this server.
http://localhost/codeigniter/pages/view
But i try with index.php in url..The page shown normally..
http://localhost/codeigniter/index.php/pages/view
Is that .htaccess problem or i have to change some other files..?
How to get rid of this problem?
Any Suggestions, acceptable.
Update
I am using ubuntu 3.10
I used the following command to enable module rewrite
sudo a2enmod rewrite
The result as follows
Module rewrite already enabled
I changed the permissions in
/etc/apache2/sites-enabled/000-default
As
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After changing this file also no luck..
Finally i found the answer to my question.As the below .htaccess solved my problem..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?/$1 [L,QSA]
</IfModule>
Thanks to all..
in your httpd.conf (on windows)
uncomment below line
LoadModule rewrite_module modules/mod_rewrite.so
in ubuntu
enable mod_rewrite using sudo a2enmod rewrite
Restart apache after making changes
Make this changes
In config.php
$config['index_page'] = '';
IN root .htaccess file
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|themes|utils|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
Nobody mentioned change the setting. In your httpd config file find and change it like this
<Directory "/var/www/html"> # your DocumentRoot setting
Options FollowSymLinks
AllowOverride All # default is None
Order allow,deny
Allow from all
</Directory>

Defining Document Root in Apache2/Cake PhP

I have a broken Cake PHP site that I did not write, but am charged with fixing. I have the main controller up, however no css/js/images, and when I click a link I get a 404 not found. I believe something is incorrect with mod_rewrite or the docroot config in apache.
While reading through Cake documentation, I came across this:
"app/webroot
In a production setup, this folder should serve as the document root for your application. Folders here also serve as holding places for CSS stylesheets, images, and JavaScript files."
In my /etc/apache2/sites-enabled/this-site, I see this:
DocumentRoot /u02/data/docroots/this_site
<Directory /u02/data/docroots/this_site>
Options -Indexes
AllowOverride none
Order deny,allow
Allow from all
</Directory>
So, my question:
does the above config block need to have:
/u02/data/docroots/this_site/app/webroot as the DocumentRoot and ?
Anywhere else you can think to look for troubleshooting this?
Since you have access to edit the apache config files - it's most appropriate to make a standard production install.
Fixing the docroot
does the above config block need to have: .../app/webroot as the DocumentRoot
Assuming that path exists: yes.
This will fix the broken css/js/images.
Fixing mod rewrite
Put the rewrite rules in the virtual host config:
DocumentRoot /u02/data/docroots/this_site/app/webroot
<Directory /u02/data/docroots/this_site/app/webroot>
Options -Indexes
AllowOverride none
Order deny,allow
Allow from all
// added
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
This will then route requests for anything that's not a file to the application.
Verify that the rewrite rule used is compatible with the version of CakePHP in use, the above is based on the rule for the latest release - it changed over the years and using the wrong rewrite rule may have unexpected side effects.
What's actually broken
AllowOverride none
This prevents the .htaccess files from being read by apache. If you were to change this to AllowOverride all, and assuming the currently-ignored .htaccess files exist, the site would work - but as a development install.
Try this:
<VirtualHost *:80>
ServerAdmin xxxxxx#test.ro
ServerName test.ro
ServerAlias www.test.ro
DirectoryIndex index.php
DocumentRoot /u02/data/docroots/this_site
ErrorLog /u02/data/docroots/this_site/error.log
CustomLog /u02/data/docroots/this_site/access.log combined
<Directory "/u02/data/docroots/this_site">
Options -Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And you should have 3 .htaccess files:
/u02/data/docroots/this_site/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
/u02/data/docroots/this_site/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/u02/data/docroots/this_site/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Hope this helps ;)

How to remove index.php in codeigniter on ubuntu server?

I have researched on all the question on stackoverflow to remove index.php from codeigniter but still i am unable to do it. Only landing page opens but rest of the pages are blank.
I m using own ubuntu linux server.
My rewrite module is also on. I tried $config['uri_protocol'] with all possible values. AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO.
My htaccess code is here
RewriteEngine on
AddType text/x-component .htc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
vhost file is here
DocumentRoot /home/black-sheep/black-sheep.org
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /home/black-sheep/black-sheep.org/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
My website url is
http://black-sheep.org/
This is the path when i echo __FILE__ on index.php
/home/black-sheep/black-sheep.org/index.php
Its amazing that wordpress site on same server without index.php is running good with following htaccess.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried with this htaccess also but it doesn't work for me.
Please suggest me the solution.
Thanks in advance
I have same problem. And I fix it.
You must add .htaccess file in root directory of your site
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And main you must change site conf in /etc/apache2/apache2.conf. Search Directory /var/www/
Change AllowOverride None -> AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
How to remove index.php in localhost(Ubantu) using codeigniter
sudo nano /etc/apache2/apache2.conf
write this code below.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
within codeigniter framework config/config.php
In application/config/config.php change:
$config['index_page'] = 'index.php';
to:
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/code_test';
make .htaccess file main folder directory
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Try this solution.
Paste this below code into .htaccess file and move it to you codeigniter folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I was facing the same problem but able to correct it. I am giving you the full instruction. follow step by step..
First check whether mod_rewrite is on or not from Terminal by typing the below command :
sudo a2enmod rewrite
Then open file apache2.conf which is located in the below mentioned directory
/etc/apache2/apache2.conf
Find <Directory /var/www/> in the file and change AllowOverride None to AllowOverride All
If it is not allowing you to save the file, that means the directory don't have the required permission. so please give that by running the below command.
sudo chmod -R 777 /etc/apache2/ and then save the file.
Now write your .htaccess file and save the file by placing the below codes.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Then restart your apache service once by the below command
sudo service apache2 restart
Hopefully, then it will work...

Why am I getting these Silex 404's?

Just getting started with Silex and having some issues.
Downloaded the fat zip file, unzipped it into wamp's www folder. So, here's C:\wamp\www\fat-silex\web\index.php:
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello', function() {
return 'Hello!';
});
$app->run();
Problem is I'm getting Apache's 404's for http://localhost/fat-silex/web/hello, and also for any URL except localhost/fat-silex/web, where I'm getting Silex'es 404 (as expected). I guess the requests go directly to Apache, and are not routed by Silex. This looks like the problem could be solved with a .htaccess file, so I added this one, suggested in the official documentation:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /fat-silex
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
However, it doesn't seem to have any effect at all.
Your rewrite base should be /fat-silex/web
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /fat-silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I've tested it on my localhost, and it works fine
the problem is your apache conf. If you don't use virtual host you should configure apache to allow htaccess file of your project directory.
On Linux (Ubuntu) : sudo vi /etc/apache2/sites-available/default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
...
</Directory>
<Directory /var/www/fat-silex/>
AllowOverride All
</Directory>

Categories