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.

Ensuring trailing slash

September 16, 2009 2:36pm

Subscribe [2]
  • #1 / Sep 16, 2009 2:36pm

    indranil

    6 posts

    Hi,

    I’m going to use a bit of ajax magic on my posts, which needs me to have one of my templates always end with a slash (/). Eg: say domain.com/category needs to go through to domain.com/category/

    Is there any way I can ensure that that happens?

    Thank you!

  • #2 / Sep 16, 2009 5:39pm

    James Smith

    259 posts

    Assuming you’re running apache you can use this in an .htaccess file:

    RewriteEngine On
    RewriteBase /
    
    # remove the www
    RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Add a trailing slash to paths without an extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule ^(.*)$ $1/ [L,R=301]
  • #3 / Sep 17, 2009 3:05pm

    indranil

    6 posts

    Hi,

    This works rather well, but instead of the URL, it gives the full filename path.. like http://domain.com/home/domainuser/public_html/category/

    Is there any way to rectify that?

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

ExpressionEngine News!

#eecms, #events, #releases