.htaccess is not working in codeigniter - php

I have started working with codeigniter and wanted to remove index.php in the URL /testing_palace/index.php/home to /testing_palace/home, working in localhost.
I google'ed the problem and tried the solutions suggested but didn't worked for me.
I changed base_url and index page in config to
$config['base_url']= 'http://localhost/testing_palace/';
$config['index_page'] ="";
And checked mod_rewrite on windows apache is enabled.
Here is my .htaccess code
RewriteEngine On
RewriteBase /testing_palace
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
All these solutions is not working for me getting not found Error.

Have your /testing_palace/.htaccess like this:
RewriteEngine on
RewriteBase /testing_palace/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
then in /testing_palace/application/config/config.php you need to have these config settings:
$config['base_url'] = '';
$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]
I think it will help you.

Related

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 in codeigniter -htaccess

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']).'/');

CodeIgniter .htaccess remove index.php on Server

I know there's a lot of questions and answers here but I'm really confused and I couldn't fix my problem yet. Please help!
I can easily access my controller via this url:
http://www.example.com/new/index.php/welcome
but I can't get it via this URL:
http://www.example.com/new/welcome
I'm configuring my CodeIgniter site in a subdirectory "new" and on my server, my directory structure is:
/
htdocs
new
/ (this is empty), htdocs(here is my directory named as "new" and new(this is the exact folder where I've my codeIgniter files.
I'm confused here about "/" and "htdocs", I think this is the thing which I'm not able to handle because my domain example.com is pointing to htdocs i.e if I put index.php in htdocs, example.com will load index.php.
my .htaccess file in "new" directory is :
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
in config/config.php:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I've tried $config['uri_protocol'] for "Auto", "REQUEST_URI" and "QUERY_STRING" etc.
With this configuration I'm able to remove index.php in my local host but I can't fix it on server. Please help!! Thanks in advance.
this one worked for me
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
make sure to remove index.php from appliation/config/config.php
$config['index_page'] = '';
put this code in .htaccess file inside new directory
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And dont forget to remove whitespace from:
$config['index_page'] = ' ';
Try with this code in .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Try either changing the
$config['uri_protocol'] = 'PATH_INFO';`
or changing the rewrite rule to use the query string instead:
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1
Then setting the protocol to query string:
$config['uri_protocol'] = 'QUERY_STRING';`
If you say that it's working on localhost, then it might be a server problem. Check if the server mod_rewrite is on by writing phpinfo(); somewhere in your view code. If it's not on and you don't have permissions, contact your host admin.
This code works for me:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
And the config.php
$config['index_page'] = '';
Try adding ? after index.php in htaccess,
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Removing index.php of codeigniter on local

I'm trying to remove index.php,in my localhost, but it seems doesn't working,its on http://localhost/testing.
I put .htacces in 'testing' directory under the htdocs.
LoadModule rewrite_module modules/mod_rewrite.so
at Apache/conf also already unchecked.
Here my .htaccess:
RewriteEngine On
RewriteBase /testing/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /testing/index.php/$1 [L]
Here my config:
$config['base_url'] = "http://localhost/testing";
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
When I access login controller, it's not found.
Not Found
The requested URL /testing/login was not found on this server.
I really don't know what to try next. Any help would be appreciated.
Try this :-
Config.php :-
$config['base_url'] = 'http://localhost/testing/';
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Your htaccess should be like
RewriteEngine On
RewriteBase /testing/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
There's no need to append /testing/ since RewriteBase already takes care of that.
basically the index.php is included in all URLs:
we can remove this using .htaccess with a simple rules. following is an example of such a file, using the "negative" method in which everything is redirected,
RewriteEngine on
RewriteBase /testing/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
now restart your server and check
Leave out the trailing slash in RewriteBase:
RewriteEngine On
RewriteBase /testing
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
$config['base_url'] should be http://localhost/testing/
$config['index_page'] should be blank.
Try this one in the .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|resources)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
ErrorDocument 404 /mainpage
your config file is fine
Difference being the "?" after index.php
You may also want to try changing the value of $config[‘uri_protocol’] in ./application/config/config.php. Sometimes CodeIgniter gets it wrong. Changing it to PATH_INFOmight work.

Codeigniter without index.php changing in config and .htaccess not working

I have this issue with codeigniter for my subdomain where I would like to take out index.php but is not working for some reason.
I have set .htaccess with below:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|user_guide|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
and also config.php index_page settings have been changed like below:
$config['index_page'] = '';
do you know why it's not working?
And this is mine
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
This is how mine is currently setup, hope this helps.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Categories