ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

trailing slash

October 25, 2012 6:04pm

Subscribe [2]
  • #1 / Oct 25, 2012 6:04pm

    MikeCJ

    47 posts

    My goal is to have each directory URL end with a trailing slash and each file URL end without one.

    Each internal link is written as an absolute URL followed by a trailing slash:
      1. The site index page: http://mysite.org/
      2. For each template group: http://mysite.org/template_group/
      3. For each template: http://mysite.org/template_group/template/

    When these links are referenced IE and Safari display all URLs with trailing slash. MOZ and Chrome display all URLs with trailing slash except for the site index page which is displayed without the trailing slash. Is this controllable or just a browser function?

    The only URLs I can control with a trailing slash are these internal links (with the exception of MOZ and Chrome on the site index page). How do I make sure other URLs will have a trailing slash when displayed in a browser?

    I am also not sure what URLs are actually files. I believe I remember that any URL generated through EE is NOT a file. Is this true? If so, how do I make sure every URL generated through EE ends with a trailing slash?

    I have entered the following code in the .htaccess file:

    #Code to add trailing slash
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !example.php
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ <a href="http://mysite.org/$1/">http://mysite.org/$1/</a> [L,R=301]

    But it doesn’t seem to do anything. When I type

    <a href="http://mysite.org/template_group">http://mysite.org/template_group</a>

    in a browser I want the browser to add the trailing slash but it doesn’t.

    Where and how do I control the trailing slash.

    Thanks,
    MikeCJ

  • #2 / Oct 29, 2012 10:52am

    Shane Eckert

    7174 posts

    Hi MikeCJ,

    Thank you for posting your question.

    The trailing slash will need to be handled in the htaccess file. This is outside of support, but I have seen the following work.

    # this adds trailing slash
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !(.*)/$
        RewriteRule ^(.*)$ $1/ [R=301,L]

    Just make sure the Control Panel is consistent.

    The results will vary from browser to browser.

    You may also want to think about asking this in the Community Help Forum.

    Cheers,

  • #3 / Oct 29, 2012 11:09am

    MikeCJ

    47 posts

    Shane,

    Thank you; I will post in the Community Help Forum.

    You say to make sure the Control Panel is consistent. What exactly do you mean? The only thing I know to do is to put a trailing slash at the end of EVERY URL throughout the CP. This is based on my assumption that NO URL within EE is considered a file; is this correct?

    Where else is the trailing slash controlled withing the CP?

    Thanks,
    MikeCJ

  • #4 / Oct 30, 2012 12:13pm

    Shane Eckert

    7174 posts

    Hey MikeCJ,

    You are right, that is what I mean. Everywhere there is a URL path, make sure it has the trailing slash, just for consistency. And remember that the config file overrides anything in the Control Panel, so if your Control Panel looks good but you are overriding a path in the config.php file, then that will take precedence.

    Does that make sense?

    Cheers,

  • #5 / Oct 30, 2012 12:55pm

    MikeCJ

    47 posts

    Hey Shane,

    I added this to .htaccess:

    #Code to add trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ <a href="http://mysite.org/$1/">http://mysite.org/$1/</a> [L,R=301]

    IE and Safari are adding trailing slashes to each URL that I’ve tested. But MOZ and Chrome add trailing slash to every URL I’ve tested except:

    mysite.org/

    In looking through the config.php file this looks like the controlling code:

    /*
    |--------------------------------------------------------------------------
    | Base Site URL
    |--------------------------------------------------------------------------
    |
    | URL to your CodeIgniter root. Typically this will be your base URL,
    | WITH a trailing slash:
    |
    | <a href="http://example.com/">http://example.com/</a>
    |
    */
    $config['base_url'] = '';

    Am I supposed to put a forward slash in between the single quotations? Please advise.

    Thanks,
    MikeCJ

  • #6 / Oct 31, 2012 12:41pm

    Shane Eckert

    7174 posts

    Hey MikeCJ,

    No, you can leave that alone. But it would be the entire URL.

    That is really odd. The other browsers handle things differently?

    Are you able to check out the logs and see what is entered there when viewing the site in different browsers?

    HTACCESS stuff is no fun.

    Thanks,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases