How should I minimize url in CodeIgniter 2.2.3 - codeigniter

I am new in codeigniter and I love to use it in my future projects too.
I having a big time problem to make my url user friendly.
I have a website running that has a lot of pages, so URLs get too big and they look too bad.
So what I want to do, is shorten my URLs. For example:
www.abc.com/index.php/main/home
I want to make something like this:
www.abc.com/home
So my question is, How should I do this thing in CodeIgniter 2.2.3 ? Is there any demo?
I was see so many links for it but it can not full fill my requirement so please help me..

You can use routes for this purpose
To remove index.php use .htaccess with following code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in config.php
$config['uri_protocol'] = 'AUTO';
now in your routes application/config/routes.php
$route['home']='main/home';

To remove index.php, place .htaccess outside application folder (root)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
To short URL, use config/routes.php
$route['home'] = "main/home";
Ex:
To use this I'm Moving

Firstly i create .htaccess file and put this code in it..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /xyz.co/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
than go to application/config/routes.php and put below code.
$default_controller = "auth";
$controller_exceptions = array('main');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = 'error';
$route['translate_uri_dashes'] = FALSE;
and in config.php
$config['uri_protocol'] = 'AUTO';
thats all...

Related

CodeignIter with HTTPS page not rendering domain/H.html not working(404 Error)

Website is normally working without HTTPS.
with HTTPS only homepage is working but other pages like (https://domain.in/contact.html) not working(404 Error Page)
My Files.
application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
.httaccess file is
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Please suggest me what to do.
Thanks in Advance.

removing index.php in hmvc

i want to removing index.php in hmvc code igniter , when i type the url without index.php it's running well but when i process to other controller the url is automatically showing index.php after my codeigniter folder.
example i type :
localhost/ci_hmvc/user/login
and the result when i process to other controller is :
localhost/ci_hmvc/index.php/user/dashboard
and my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ci_hmvc/index.php/$1 [L]
</IfModule>
please any one help me
You can make changes in config.php which is in config folder
You can see the line
$config['index_page'] = 'index.php';
Change this line in to
$config['index_page'] = '';
I hope this will helps you
put this code in .htaccess and place the htaccess file to the root of the folder..
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

Remove index.php from Codeigniter URL in Wamp

I have big problem trying to remove index.php from url's
i have searched lots if forums (this also), but no help for my situation.
so i have config.php file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
my .htaccess file in public_html folder near index.php.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
i have rewrite_module ON (and it's working) and my httpd.conf AllowOverride set to All
so when i am going to mydomain.com/controller/action - I get 404
but when i go to mydomain.com/index.php/controller/action - everything is OK..
i have tried lots of .htaccess examples... and so on.. nothing helps..
.htaccess (This should be place outside application folder)
Paste this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Note : Sometime index.php will not remove in windows. But if you upload it to server it will work fine. This happen me too in XAMPP but if i upload it to host(Linux) it works fine
My Config which is working fine :
config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
.htaccess
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

CodeIgniter Deployment

MySite in my PC is http://localhost:8080/MySite/MyController
when I deploy to hosting server, I can only access
http://subdomain.MyDomain.com/MySite/MyController but not http://subdomain.MyDomain.com/MySite/MyController/AnyFunction (it gave 404 error)
I have created .htaccess to remove index.php, it works fine in my PC;
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I also set $config['uri_protocol'] = 'REQUEST_URI';
Local setting:
$config['base_url']='http://localhost:8080/MySite/';
$config['index_page'] = '';
Hosting setting:
$config['base_url']='http://subdomain.MyDomain.com/MySite/';
$config['index_page'] = '';
Can anyone advice where have I gone wrong?
TIA.
Maybe you need to add a question mark to your rewrite rule:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
source: http://codeigniter.com/forums/viewthread/181440/#862893

codeigniter removing index.php (possible problem with host)

Hi everyone I'm having some problems when removing index.php in CodeIgniter.
I created my application locally and it works fine but when I uploaded it, removing index.php doesn't seem to work.
I have a feeling this could have something to do with my host, it's not the best and I've had problems before. It's hosted on Fatcow.
So..
all my CodeIgniter files are located in a sub-dirctory called outfitr. e.g
<root>/outfitr/
I have my .htaccess file located in this folder with the following taken from the CI wiki:
EDITED
RewriteEngine On
RewriteBase /outfitr/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
changes fo my config.php look like the following. I have enabled query strings as I need them for a section of my application.
$config['base_url'] = "<host>.com/outfitr/";
$config['index_page'] = "";
...
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
Any help would be great. As I said I think it might have something to do with the host Fatcow.
I have tested mod_rewrite, following the steps on the following page and it seems to be enabled.
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html
ok so after some trial and error I finally got it working. I setup my .htaccess file as follows. Note the '?' in RewriteRule.
RewriteEngine On
RewriteBase /outfitr/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
Then in config.php I set
$config['uri_protocol'] = 'REQUEST_URI';
Think this is down to the way some hosts setup their mod_rewrite module. Dreamhost and hostgator have the same problem.
http://codeigniter.com/wiki/mod_rewrite/
If your installation is not in the server root you will need to amend the RewriteBase line from “RewriteBase /” to “RewriteBase /folder/”
The current .htaccess you have is re-routing all requests to /index.php, which as you said yourself is not there. You want them to route to /outfitr/index.php.
You can do this by changing the RewriteBase /outfitr/
If not, please give more detail.

Resources