Search code examples
.htaccesshttp-redirectcodeigniter-url

url redirect, change it in codeigniter or change .htaccess


i have to redirect one url to another. http://www.abc.com/realestate/ to Redirect to http://www.abc.com/businessfinder/company/4105/Property_Agent/. is it better to change on the codeigniter routes.php or the .htaccess file?


Solution

  • If you know that a URL should be redirected then there is no reason to hand the request to PHP. So, redirecting using the .htaccess file would be preferable.

    If you have mod_alias installed then you can use the Redirect directive:

    Redirect 301 /realestate/ http://www.abc.com/businessfinder/company/4105/Property_Agent/
    

    You can also use mod_rewrite to jump between places in various ways. E.g.:

    RewriteRule ^/realestate/?$ /businessfinder/company/4105/Property_Agent/ [R=301,L]
    

    If that is not possible then you can use CodeIgniter's $this->url->redirect() method. It will send the user to any website you like.