Make URL Suffix optional in codeigniter with .php and without .php

844 views Asked by At

My project is almost complete so I cannot make changes in url throughout project.whenever I use redirect like

redirect('welcome?loggedout=true', 'refresh');

Page get redirected to

welcome?loggedout=true.php

I have added URL suffix

$config['url_suffix'] = '.php';

But can I use it as optional and url remains normal with extension until I want to customise a link with .php.

2

There are 2 answers

0
Felipe Lima On

Just to complement and update, you can use suffixes for some URLs only and not all your project - using routes from codeigniter. OP mentions this on his comment but provided no examples.

Here's a example: http://antsplace.co.uk/url-suffix-in-codeigniter/

I did not do the same thing. In my case, I just needed suffixes for .xml pages So I only put, on routes.php :

$route['newsfeeds/(:any)\.xml'] = 'newsfeeds/index/$1';

And created a Newsfeeds controller and index function to handle. That's it. That way only URLs with /newsfeeds on segment 1 will allways apply/accept .xml suffix

index controller function is likely many others:

public function index()
    {
        $this->load->helper('xml');
        $this->load->view('xml_view');
    }

Don't forget to call header("Content-Type: application/rss+xml; charset=utf-8"); in your site header to properly render xml to this views or you can do this with codeigniter inbuilt function as described in: https://stackoverflow.com/a/10361155/2387741

And at last this xml helper (docs here) help you translate some characters that need correct formatting on xml to work properly.

I guess this is it. Best regards.

0
Abdulla Nilam On

In order to use Query String URL’s, edit config.php which is located in application/config. Set enable_query_strings to TRUE and define controller and function trigger.

$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

Output

enter image description here

Go through this source