Welcome Guest, Not a member yet? Register   Sign In
Overriding $config['url_suffix'] in specific controllers/methods
#1

[eluser]Roger Glenn[/eluser]
PROBLEM
The majority of my URLs need a trailing slash so I set the url_suffix to '/' in my config file.

Code:
/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| http://ellislab.com/codeigniter/user-guide/general/urls.html
*/

$config['url_suffix'] = '/';

But I need to remove the trailing slash on a few important URLs.

I am using CI to dynamically generate various sitemap.xml files through a sitemap.php controller, so I declared the following routes in my routes.php file:

Code:
// sitemaps
$route['sitemap-index.xml']     = "sitemap";
$route['main-sitemap.xml']      = "sitemap/main";
$route['locations-sitemap.xml'] = "sitemap/locations";
$route['artists-sitemap.xml']   = "sitemap/artists";
$route['venues-sitemap.xml']    = "sitemap/venues";

But because I've set the $config['url_suffix'] = '/' these .xml URLs getting a trailing slash, ex.

Code:
http://domain.com/sitemap-index.xml/

Whenever I remove the slash from my browser's address bar and hit enter I always get re-routed to the version with the trailing slash.

POSSIBLE SOLUTION
I've tried overriding the config item in the sitemap.php controller constructor like so

Code:
function __construct() {
parent::__construct();
$this->config->set_item('url_suffix', '');
}

...but that has no effect.

Is there a hidden framework method I can use to remove the $config['url_suffix'] from specific URL's in my application?


Messages In This Thread
Overriding $config['url_suffix'] in specific controllers/methods - by El Forum - 07-13-2012, 11:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB