How to remove index.php from URL in CodeIgniter using .htaccess - php

I know this question is asked many times before and I've gone through most of them already but couldn't find a solution. I've tried most of the answers given here, here and in CodeIgniter official documentation. And restarted apache each time. It didn't work for me. mod_rewrite is already enabled in my apache server.
Weird thing is, I've a working example for WAMP (in my laptop):
<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 /project/index.php
</IfModule>
It works perfectly in WAMP, but it doesn't work in LAMP. Any kind of help is appreciated.

Please use below code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I have used this and it is working.

Try Below code in your .htaccess file
<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>
<Directory "/path/to/document/root/">
AllowOverride All
Allow from All
</Directory>

Just like this......
.htaccess inyour root directory with following code..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Set configuration in application/config.php as follows..
$config['base_url'] = 'http://domain_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

I made it working with the help of following .htaccess code:
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
And I updated <Directory /var/www/> section of /etc/apache2/apache2.conf file with:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
It solved all problems and now it works fine.

here it is my approach:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And also in config.php replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
and also in the same file replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"

Related

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 in Codeigniter 3 apache2 server

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>

eror .htacces Codeigniter on webserver

I have code .htacces that familiar when you using Codeigniter like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
But its not work. like this.
When I delete this .htacces, the code running well. I have been check mod_rewrite on apache is enable. I'm confused, need help please
TRY THIS
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Note: projectname is your root folder name
Even though you have mod_rewrite enabled, there is still a setting that can prevent .htaccess from working.
Check your httpd.conf file and make sure that in the directory settings that
AllowOverride None
is changed to
AllowOverride All
If you need more details than that, just ask! I've kept this very brief.
Try this in .htaccess
RewriteEngine on
RewriteBase /ci
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and in application/config/config.php
$config['index_page'] = ''; // make it empty.

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>

remove index.php from the url in Codeigniter on host server

Hi all im trying to hide the index.php from the url, well something like that:
i want : mydomain.com/index.php/mycontroler
to be like : mydomain.com/mycontroler
here is my .htaccess
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
And here is my conf.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
the problem is that it was working good in the local but not in the server
here is the disposition of my files
- bin
- etc
- mail
- public_ftp
- public_html
-- application
-- assets
-- system
-- .htaccess
-- index.php
Help guys
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
if still getting troubles try changing :
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'AUTO';
or somenthing different more (in the config.php you'll find all the options available to try for the uri_protocol param)
Here is .htaccess stuff,
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory browsing
Options All -Indexes
IndexIgnore *
And in config.php
Set base URL like 'http://www.example.com/'
Set $config[‘index_page’] to an empty
string Set $config['uri_protocol'] = 'REQUEST_URI'
all my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|static)
RewriteRule ^(.*)$ /index.php/$1 [L]
and you should make sure that property AllowOverride is set correct, eg:AllowOverride ALL in your httpd.conf Directory segment
Make the below changes in the root .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
It worked for me.

Categories