remove index.php not working on aws EC2 server - codeigniter

I am trying to remove index.php of my codeigitor application which is hosted on EC2 instance of ubuntu OS. But unable to get the solution.
Below is my htaccess file added to the root of my application
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|js|font|woff|ttf|svg|eot|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Thanks

Add .htaccess file in you CI root folder and add this code
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Remove idex.php from CI
$config['base_url'] = '';
$config['index_page'] = '';
Then
sudo nano /etc/apache2/apache2.conf
and change:
<Directory /var/www/>
AllowOverride All
Restart the apache

Related

how to remove index.php from codeigniter url using window rdp (tried many solutions)

I know this question has been asked many times but have tried all the solutions but invain
My Config file is as follow
$config['base_url'] = 'http://immodernafrican.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess file is
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
RewriteRule ^(.*)$ index.php/$1 [L]
Changed
AllowOverride None
To
AllowOverride All
but still my url works with index.php
immodernafrican.com/index.php/AncientHistory
other than that it gives 404 error
immodernafrican.com/AncientHistory
Just Change your .htaccess to this
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Your .htaccess file will be
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
#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>
<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>
Config file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Follow this
For Server
Activate mode_rewrite module
sudo a2enmod rewrite
Restart the apache
sudo service apache2 restart
edit 000-default.conf
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server:
sudo service apache2 restart
in config.php
$config['base_url'] = 'http://immodernafrican.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
in routes.php
$route['default_controller'] = "YOUR_DEFAULT_CONTROLLER";
htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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
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>

Why can I not remove index.php from codeigniter URL

I have a new installation of Kubuntu 15.10 with old (working) code from my site.
Somehow I can not get rid of the index.php in the URL.
I tired dozens of suggestions but nothing seems to work.
My current status is this:
Apache 2 have mod_rewrite on:
printout of php_info()
Apache2 config is:
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
My .htaccess is located under application folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
What am I missing here? I am loosing faith... :-P
Step 1: In your .htaccess replace all other codes..try with this:
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Step 2: Move your .htaccess from application folder to where index.php located.
Step 3: Change in your config.php
From:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Try it in application/.htaccess, index.php will exists in url but in scripts it will be ignored.
# 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_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

Unable to load website on url it open when I enter **www.domain.com/controller**

I have developed the application in CodeIgnitor CI. Website id running properly on local machine.
my htaccess code is below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ROOT DIRECTORY NAME/
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And my directory structure is
|application
|css
|js
|htaccess
|index
I have given the controller name in route.php for default_controller
Please let me know were I am wrong?
Oppz, In your file folder structurer you forget to upload system folder. It will solved all your issues.
and in config/config.php (Change this)
$config['base_url'] = '';
$config['index_page'] = '';
In .htaccess(out side the application folder) replace this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

In codeigniter redirecting is not working without index.php?

I am new to codeigniter while redirecting a page index.php is not loading by default,So i have tried the below code in htaccess file. I have installed php 5.3.10, apache server and postgres database. so if any new configuration have to be done apart from changing .htaccess and httpd.conf then please let me know. I have seen previous questions asked on the same issue and i referred everything from those questions but still I am not able to solve this. please let me know what extra things to be done.
.htaccess file
<IfModule mod_rewrite.c> RewriteEngine On #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|public|images|robots\.txt|css) RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^/(index\.php|assets/|humans\.txt) RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
httpd.conf file
ServerName localhost
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Following things you should do for avoiding index.php in url
Always make sure you have .htaccess file. which you have already.
Include contents in .htaccess which #charlie has suggested above.
Edit httpd.conf file using nano command and include main thing keep allowoveride All
First disable rewrite mode and enable it again then restart apache2 server using following commands.
sudo a2dismod rewrite //which disables the rewrite mode
sudo a2enmod rewrite //which enables the rewrite mode
sudo service apache2 restart //which restarts your apache
Thats all you need to do. All the best.
Paste this in your .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

CodeIgniter - removing index.php

Im having some trouble removing the index.php thing on my CI install, the current .htaccess im using is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My CI install is back from the public_html directory and i have changed the config to
$config['index_page'] = "";
So my CI looks like the following
/core-1.7.3
/public_html/index.php
When i type the url i get the 404, but when i put index.php in front of it, it works fine :S
Im confused
Hi
I ve installed that 1.7.3 and this .htaccess worked with this URL-
/CodeIgniter_1.7.3/public_html/welcome
.htaccess->
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Work through Avisek Chakraborty's comment and make sure you've done them all, but
it sounds to me like you don't have mod_rewrite installed correctly.
Make sure it is by using the following test:
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html
It is written for windows but you should get the idea.
If it doesn't work then install mod_rewrite and try again.
Also try to change this:
$config['uri_protocol'] = “REQUEST_URI”
You need the FollowSymLinks directive for .htaccess rewrites ...
Options Indexes FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The Options directive is in The Apache Docs

Resources