Removing index.php in codeigniter -htaccess - php

Im trying to remove index.php from the url for the past 4 days but not successful.
http://domainName.com/CI/index.php/controller-name/function/parameter
CI is the folder hosted in godaddy.
/
.htaccess
CI
After googling, I tried with the following codes but getting only a blank page or error:500 and also I didn't understand the logic. Please someone help me to find where Im going wrong.
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
2nd
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I also changed the line in, CI/application/config/config.php
$config['index_page'] = '';
$config['uri_protocol'] = “REQUEST_URI”

This should work
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ CI/index.php/$1 [L]

Just try this it's working means reply me
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Follow the following step:
Change the config file like this:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Use the following .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 vary depending on server. Some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
see here
Use the following code in base_url:
$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');

Related

Codeigniter remove index.php from URL localhost:82/project

I have URL
http://localhost:82/project/index.php/home
I want to remove index.php from above url.
Like this : http://localhost:82/project/home
I have used many solution
1) I have remove index.php from config.php file :
$config['index_page'] = '';
2) change "uri_protocol" in config.php file :
$config['uri_protocol'] = 'REQUEST_URI';
My htaccess :
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Anybody master here to solve my question ? Thanks in advance.
use this Codeigniter .htaccess file and install it to your root app.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Like this one...
project_name
-application
-assets
-system
-user_guide
-.htaccess // like this one
Try To Use This
RewriteEngine on
#RewriteBase /project/
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
I use it and work on me.
Thank You
Set your base URL in config as
$config['base_url'] = 'http://localhost:82/project/'
In your .htaccess, Try with this, I have used this in my CI projects.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Place this file in your project folder.
If you are using Apache Server, you must do mod_rewrite enabled. And then modify your .htaccess file with the code below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
For more information, visit here
Try similar question here

Is it possible that ci url will not work with index.php

Is it possible that ci url will not work with index.php.I dont want to add index.php in url. If someone adds index.php in url it should not work.I have tried many methods . Please give me suggestion.
I have tried but it's not working
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
for e.g
if i use below url This should work..............
`example.com/abc`
if i use below url shouldn't work
`example.com/index.php/abc`
Create .htaccess file in your root directory And keep this code into it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Open application/config/config.php
//find the below code
$config['index_page'] = "index.php"
//replace with the below code
$config['index_page'] = ""
/find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
You can use:
RewriteEngine On
# 403 Forbidden for index.php
RewriteCond %{THE_REQUEST} index\.php [NC]
RewriteRule ^ - [F]
# Rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In Config.php
$config['base_url'] = 'http://localhost/website/';
$config['index_page'] = '';
# If Live site
# $config['base_url'] = 'http://stackoverflow.com/';
In .htaccess
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]
Check my answer on another question Set up the base URL in codeigniter
Try the following code than..
change the following in config.php
$config['index_page'] = ""
$config['uri_protocol'] = "REQUEST_URI"
Now open .htaccess file and replace with 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]
if above index line do not work the replace the line with new code. Because .htaccess depend on server
// Replace last .htaccess line with this line
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Add below code in the top of the index.php. I think this will solve your problem.
if(strpos($_SERVER['REQUEST_URI'],'index.php') !== false){
header('location: http://xyx.com/404');
die();
}
Try with below rule,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,END]
RewriteRule ^index\.php* - [F]
What exactly do you mean by saying url shouldn't work should it redirect to another or be replaced?
url shouldn't work - i think you must say to a user (to a crawler) that there is an error in this link, if the link is already indexed, tell crawler that this is 404 not found page, and it will stop indexing that pages. You can't disable index.php/foo totally, because all requests are going through index.php (i believe, if you are using routing)
Here is replacement example - https://htaccess.madewithlove.be?share=04dcf45c-32e9-5c29-b706-5869cd369ffd
Input url http://ex.com/index.php/abc
RewriteEngine On
RewriteRule index.php/(.*) /404 [L] #send user to not found page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Output url http://ex.com/404
Just change your root .htaccess file:
RewriteEngine on
RewriteBase /projectname
# 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]
Change in config file:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

Codeigniter: how to remove index.php from URL?

I've looked at many articles and tried different ways but it still doesn't work.
Now my URLs look like mysite.com/index.php/[controller].
The goal is mysite.com/[controller].
In config.php:
$config['index_page'] = "";
$config['uri_protocol'] = 'REQUEST_URI';
My .htaccess file contains
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Also mod_rewrite is enabled in my Apache server.
Any other solutions?
In application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
in .htaccess (Place Outside application folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Update 2018-02-27
$config['base_url'] = 'https://stackoverflow.com/'; # Must fill
else you get this error Codeigniter echoing [::1] instead of localhost
use this .htaccess
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]
Refference
try this in your config file
$config['base_url'] = '';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
This one is working fine for me, you can try with this
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
This works for me [in linux operating system]:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
in config file use your project url in base_url
$config['base_url'] = 'http://localhost/project';

Removing index.php from url in codeigniter

I tried to remove index.php from url. I tried more links from linkden but have not worked. I tried following.
1.add .htaccess file with following data,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
2.changed in config.php $config['index_page'] = '';
3.activate mod_rewrite.
But still not working.
Make .htaccess file in root of project directory with following contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
modify application/config/config.php with following:
$config['index_page'] = '';
Please replace your htaccess code
RewriteEngine on
RewriteBase /yourfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|img|css|captcha|robots\.txt)
RewriteRule ^(.*)$ /yourfolder/index.php/$1 [L]
Finally the Following code works in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Can't remove index.php in codeigniter redirecting to localhost.com

i have a project having url
http://localhost/myproject/
naw i have a page that is working
http://localhost/myproject/index.php/about
but i want to change it to
http://localhost/mywesites/about
but it's redirecting me to
www.localhost.com/about
my config.php file is
$config['base_url'] = 'http://localhost/myproject/';
$config['index_page'] = '';
and .htaccess file is
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
If you use a RewriteBase in your htaccess like this:
RewriteBase /mywesites/
...does that work?
Replace Your .htaccess file with this code and try :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

Categories