0

If a user follows this url:

http://localhost/events/info.php

How can I remove the .php extension via htaccess so the user gets routed to index.php and my Events Controller into the Info function? I basically want to create 301 redirects.

http://localhost/events/info

I have old indexed links that I need to redirect to my controller functions so I do not get 404s.

Tom
  • 602
  • 5
  • 20
  • 2
    You really just need to read the excellent [CodeIgniter documentation](http://ellislab.com/codeigniter/user-guide/general/urls.html) on URL structure. – WoMo Apr 19 '13 at 16:06
  • I understand how the URL structure works. I have old indexed links that I need to redirect to my controller functions so I do not get 404s. – Tom Apr 19 '13 at 16:22
  • I see, however the original question did not state this issue. RewriteRules in your .htaccess file are your best to way to create 301 permanent redirects. – WoMo Apr 19 '13 at 16:33
  • See this answer http://stackoverflow.com/a/15844946/1741542 – Olaf Dietsche Apr 19 '13 at 17:03

3 Answers3

1

use

RewriteEngine On
RewriteRule ^events/info/$ index.php [L,QSA]
Alex Ruhl
  • 451
  • 2
  • 6
  • 16
0

What version of CI you are using?

normally we already got like this without .php

http://localhost/events/info

To route to index.php (in view folder): you only need to do like this in your controller file.

controllers/events.php

function info(){
 redirect('events/index');
}

function index()
{
 $this->load->view('index.php');
}
Wayne Tun
  • 590
  • 7
  • 24
0

A 301 redirect can be achieved using .htaccess

Redirect 301 events/info.php http://localhost/events/info

You may find this tool useful for generating the redirects.


If you just want to route the URL: http://localhost/events/info.php to the info function in your events controller, then you don't have to remove .php from the URL, you can add a route in application/config/routes.php.

$route['events/info.php'] = 'events/info';

If you haven't already then you must also remove index.php, CodeIgniter's user guide explains how to do this.

If you'd like to remove .php from all your URLs to make them look cleaner, then there a lots of resources available, including other answers on SO.

Community
  • 1
  • 1
jleft
  • 3,457
  • 1
  • 23
  • 35