Reputation: 522
I have a CI Project where I want to change the URL like below:
www.example.com/index.php/Controller/method/param1
to
param1.example.com/index.php/Controller/method
Is this possible using just CI? Like routes. Or we need to .htaccess? If possible, are there any risks or is it a bad practice? Also does it affect SEO?
EDIT: This rewrite should happen only for Controller
controller.
EDIT: I think the meaning came out wrong. When a user enters a URL like
param1.example.com/Controller/method
It has to fire the method
in Controller
and pass param1
as parameter.
Upvotes: 0
Views: 435
Reputation: 477
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Redirect extends CI_Controller { public function index($method,$domain) { $redirect_url = 'http://www.' . $domain . '.example.com/index.php/Controller/' . $method; redirect($redirect_url,'refresh'); } } ?>
$route['Controller/(:any)/(:any)'] = 'redirect/index/$1/$2';
You are done. Enjoy :)
Upvotes: 1