way to remove "/home" just from my home page in codeigniter - codeigniter

I am new to Codeigniter.
I want my homepage to be set as "example.com" rather as "example.com/home" currently.
My routes.php is like this:
$route['default_controller'] = "home";
Everything is working fine, just need to know if there is a way to remove "/home" just from my home page. Everywhere else is fine.
.htaccess
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

In your .htaccess file use this rule:
RewriteRule ^(home(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
In your case, maybe this could be solution. Try this way:
RewriteEngine on
RewriteBase /
RewriteRule ^(home(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
php_value session.cookie_httponly 1
php_value session.cookie_secure 1

Just write in your .htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and
$route['default_controller'] = "home";
in your routes.php
and check
$config['base_url']='http://exemple.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
then example.com will show example.com/home controller but wont display the '/home' uri segment. It works fine for me

Related

Can't remove index.php from URL

I am trying to remove index.php from URL, but I keep getting error 404.
Config file:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You need one more .htaccess file in your application folder, and here is the detail of the file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Please copy and paste following code in your htaccess file and put it in root folder and application folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [L]
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Just replace
$config['uri_protocol'] ="AUTO"
to
$config['uri_protocol'] = "REQUEST_URI"
AND IN HTACCESS FILE put following code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Remove index.php from URL in CI?

I removed index.php from the URL in CodeIgniter. I have already changed the .htaccess file data. But I want to know that is there any other way to remove the index.php from the URL or through any other .htaccess data. Means this is only a way or not.
In .htaccess file I wrote this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Try This code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and do not forget to null index value in config file
$config['index_page'] = '';
Try this :
Make sure you have enabled rewrite_module on your Apache modules
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?/welcome/$1
Open config.php :-
$config['index_page'] = '';
$config['base_url'] = 'http://www.example.com/'; //your site name
$config['uri_protocol']= 'REQUEST_URI';
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php (again, not if its a real file or folder)
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>

Codeigniter error 404 on production after set_flashdata

I'm using CI on my project, when I moved it on production server, I saw the error "404 page not found" when calling $this->session->set_flashdata. This error is preserved when I requested any page until I cleared the cookies. This error repeats after call "set_flashdata" again.
function _set_success($message)
{
$this->session->set_flashdata('is_db_msg', 1);
$this->session->set_flashdata('db_msg', $message);;
}
$result = $this->page_model->edit_page($page_name, $this->_get_data_array());
$result ? $this->_set_success('OK') : $this->_set_error(DB_ERROR);
redirect(BASEURL.'admin/pages');
// server 404 (on any page) after redirect
BASEURL it's constant: DEFINE('http://mysite.com');
Also I'm using this .htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^(index\.php/?)?(.*[^/])/?$ http://mysite.com/$2 [L,R=301]
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^$ http://mysite.com [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(index\.php/?)?(.+)/$ /$2 [L,R=301]
RewriteCond %{ENV:REDIRECT_FINISH} ^$
RewriteRule ^index\.php/(.*)$ $1 [L,R=301]
RewriteRule ^(main/index(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^([^/]*)/index/?$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(system|application).*
RewriteRule ^(.*)$ /index.php/$1 [L,E=FINISH:END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,E=FINISH:END]
Please, help and sorry for my bad english.
You should use following for redirecting:
redirect('admin/pages');
or
redirect(base_url().'index.php/admin/pages');
or
DEFINE('BASEURL','http://mysite.com')
redirect(BASEURL.'index.php/admin/pages');

Mod_Rewrite Exclude a url (URI Exception)

I am using this mod-rewrite rule to redirect the just the homepage of my site to the /it/ sub-directory on the same site.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^/$ http://www.example.com/it/
However, I want to exempt this url from being redirected
http://www.example.com/?act=25
How can I write an exempt condition to do this?
Found a solution
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} !^act=(.*)$ [NC]
RewriteRule ^$ http://www.example.com/it/
Oh, and RewriteCond does not work with RedirectMatch in case you didn't know (I didn't and wasted hrs because of it)

after removing index.php from url in codeigniter

My login Controller : $this->load->view('login-view');
My link that redirects to 'login-view' is in the template is: anchor('login','Login');
Before removing index.php from url in codeigniter works well. But after removing index.php from url it is not working.
My .htaccess file is :
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
hard to expalin i think, Thats all i have got. :(
Try this in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And in config.php
$config['uri_protocol'] = 'AUTO';
Just remove index.php from your config file.
$config['index_page'] = "index.php";
should be
$config['index_page'] = "";

Resources