CodeIgniter Forums
Dynamic URL Suffix [SOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Dynamic URL Suffix [SOLVED] (/showthread.php?tid=30809)



Dynamic URL Suffix [SOLVED] - El Forum - 05-26-2010

[eluser]ranjudsokomora[/eluser]
Hello,
I am wondering if it is possible to have the URL_Suffix become dynamic. I have my URL suffix set in the config.php file as ".aspx". I would like to retain that for a majority of pages. But I would also like to do is have a URL such as:
http://www.example.tld/css/style1.css

I want to be able to track how many times a style was accessed, and by what visitor. I don't really want to parse through the server logs if I can help it.


Any pointers?


Dynamic URL Suffix [SOLVED] - El Forum - 05-26-2010

[eluser]ranjudsokomora[/eluser]
I have solved this,
I extended the CI_URI library as follows:
Code:
<?PHP
class MY_URI extends CI_URI {
    function MY_URI() {
      parent::CI_URI();
    }
    // --------------------------------------------------------------------
    
    /**
    * Remove the suffix from the URL if needed
     *
     * @access    private
     * @return    void
    */
    function _remove_url_suffix()
    {
        $index_page            =    $this->config->item('index_page');
        IF (preg_match_all('|/|',$this->uri_string,$out)>=1) {
            $uri_explode    =    explode("/",$this->uri_string);
            IF (EMPTY($index_page)) {
                $controller    =    $uri_explode[1];
            }
            ELSE {
                $controller    =    $uri_explode[2];
            }
            
            IF ($controller==$this->config->item('assets_controller'))
            {
                $this->uri_string = preg_replace("|".preg_quote(".css")."$|", "", $this->uri_string);
            }
        }
        ELSE {
            IF  ($this->config->item('url_suffix') != "") {
                $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
            }
        }
    }
}

I then added a new config item to the config.php file.
Code:
$config['assets_controller']    =    'control_file';