How to Redirect with CodeIgniter - codeigniter

I have issue with page redirection with codeigniter, I want to redirect from http://mywebsite_domain/index.php/home/show/206 , to http://mywebsite_domain/index.php/ar/home/pages/show/206 . And My controller name "pages" in "home" folder
please help me....

Just you have to write some code in routes.php in application/config/routes.php.
$route['show/(:any)'] = 'ar/home/pages/show/$1';
See more at CodeIgniter - Routing

You can use codeigniter's URI routing.
refer the below link-
http://www.codeigniter.com/userguide2/general/routing.html
In that you can also use Regular Expressions to get generalized URI routing.
routes.php => /application/config/routs.php

Related

Codeigniter custom URL Routing

I have a URL in my Codeigniter
http://localhost:64743/index.php/mybox?name=John
I want it to look something like this
http://localhost:64743/index.php/mybox/name/John
is it posiible? how does custom URL works in CodeIgniter?
$route['mybox/(:any)'] = "mybox/index";
user above mention code in routes.php of config folder and you will get query string value by $this->uri->segment(3); and $this->uri->seggment(4);
for further assistance, please check
https://ellislab.com/codeigniter/user-guide/general/routing.html

human-friendly URL with codeigniter

I am developing web with Codeigniter. I what the url like this:
[site]/[company_name]. The [company_name] is dynamic.
For example: http://www.abc.com/alixa
But the real url is: http://www.abc.com/shop/alixa
Is there anyway can I do with this? with htaccess or route in codeigniter?
Yap you can do it from both .htaccess and routes
here is solution from using routes
$route['(:any)'] = 'shop/$1';
by using this route you will getting problem from other url as if you wants
http://www.abc.com/mysecoundController/myfunction
it will also redirect to shop controller,
For this you have to write more routes
as
$route['(mySecoundController:any)'] = 'mySecoundController/$1';
$route['(:any)'] = 'shop/$1';
here is the link for detail
http://codeigniter.com/user_guide/general/routing.html
You can check this article that include all the information that you need: http://www.web-and-development.com/codeigniter-minimize-url-and-remove-index-php/#removing-first-url-segment

How do i redirect my all old url to new url Codeigniter

I want to redirect my all old url to new url.
My few old URLs are
domain.com/
domain.com/submit
domain.com/get/soft-name
domain.com/most-downloaded
etc, etc,
Now i want to redirect my all url to
domain.com/en
domain.com/en/submit
domain.com/en/get/soft-name
domain.com/en/most-downloaded
I am using CodeIgniter. Please Suggest me some code for route.php
thanks in advance
If you want to handle this in your routing, you could just do this:
$route['(:any)'] = "en/$1";

Rewrite URLs in CodeIgniter

How can I rewrite the following urls in CodeIgniter
localhost/users/show_profile/john
to
localhost/john
Thanks
you can achieve dynamic URL using CodeIgniter Routes.
Assuming
localhost/users/show_profile/john
We're looking at:
localhost/controller/method/variable
we can use the following route:
$route['([a-zA-z_]+)'] = "users/show_profile/$1";
You can access the variable by calling $this->uri->segment(1); inside show_profile() function.
IMPORTANT: keep the $route['([a-zA-z_]+)'] at the end of the routes.php file, to make sure it's not overriding any other routes.
If you only need to do it for a defined set of URLs, update /config/routes.php
If you need it to be dynamic then you should extend the CodeIgniter Router Library.
http://codeigniter.com/user_guide/general/creating_libraries.html (look for Extending Native Libraries)
In config/routes.php add $route['(:any)'] = "users/show_profile/$1";
More info on routes here

codeigniter routes

How to redirect controllers if they not match pattern.
For example I have follow controllers about_us, contacts, find_us. How to do so If the request method is not in that selection to be redirected to other controller ?
For some reason it's not in the documentation for URI Routing in the User Guide. If you are using CI2, inside of your routes.php file you can use "404_override". It is one of the reserved routes.
$route['404_override'] = "error";
So when a user comes to a controller that is not one you have created or not something inside your routes.php file, it throws them into the "error" controller. Obviously you would have to make a controller called "error"
Read about routing.

Resources