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.

4
  • 2
    You really just need to read the excellent CodeIgniter documentation on URL structure. Commented Apr 19, 2013 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. Commented Apr 19, 2013 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. Commented Apr 19, 2013 at 16:33
  • See this answer stackoverflow.com/a/15844946/1741542 Commented Apr 19, 2013 at 17:03

3 Answers 3

1

use

RewriteEngine On RewriteRule ^events/info/$ index.php [L,QSA] 
Sign up to request clarification or add additional context in comments.

Comments

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'); } 

2 Comments

he would to change it via the .htaccess file ;)
anyway , I learn something . Cool :)
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.