End my URLs with a trailing slash (/) or not? And how do I do this with codeigniter

Hey guys, I'm trying to figure out what works best. Of the articles I read, it's best to end the URL with a trailing slash.

So instead: http://www.site.com/article

He will read: http://www.site.com/article/

First, I adjusted htaccess to force the trailing slash.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}      ^.+[^/]$
RewriteRule ^(.+)$              $1/   

Then I started to implement this in my links, and I thought that if I did the binding ("article / ',' article '), it would work, but it seems that this function separates the trailing slash.

To get around this, I changed the configuration file to $ config ['url_suffix'] = '/'. Which worked. MUCH ONLY a fine. Except that I have a document area on my site with pdf, etc. Thus, the links created there will look like http://www.site.com/documents/doc1.pdf/ . This, of course, does not work.

What do you think my decision is here? I think I could go back to any page that I referred to documents or files and configure them so that I would not use the binding function, but I feel that there should be an easier way.

Thank!

+5
source share
3 answers

. , - . "/" , ( ) , . , . , , , pdf.

- , , . , , , ?: -)

+1

, , , ( ), , . - . , ? .

0

Override site_url()from Config.phpto add trailing slash except file link:

application/core/MY_Config.php:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Config extends CI_Config {

    function site_url($uri = '')
    {   
        if ($uri == '')
        {
            return $this->slash_item('base_url').$this->item('index_page');
        }

        if ($this->item('enable_query_strings') == FALSE)
        {
            $suffix = '';
            if( ! preg_match('/(.+)\.[a-zA-Z0-9]{2,4}$/', $uri))
            {
                $suffix = '/';              
            }
            return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;              
        }
        else
        {
            return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
        }
    }

}
// END MY_Config Class

/* End of file MY_Config.php */
/* Location: ./application/core/MY_Config.php */
0
source

All Articles