cancel
Showing results for 
Search instead for 
Did you mean: 

Add trailing slash to URLs via .htaccess?

jtonline
Grafter
Posts: 83
Thanks: 9
Registered: ‎21-03-2008

Add trailing slash to URLs via .htaccess?

Hi, I have a blog which is located at:
[tt]http://ccgi.jtonline.plus.com/blog/[/tt]
It is working well with one slight exception; if you use that address to access it, but omit the trailing slash (and there's a link in my RSS feed that does this) it redirects to:
[tt]http://ccgi.jtonline.plus.com/~jtonline/blog/[/tt]
which obviously results in a Page Not Found error.
Is there something within my .htaccess file that I can change/add so that a trailing slash is added to that  URL automatically, but that won't break the rest of the site?
Here is my current .htaccess content:
# BEGIN Blog
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php
</IfModule>
# END Blog

I tried adding some code I found on a website whilst trying to fix this myself, but if I use it I get an Internal Server error 500.  Here is what I tried adding:
# If path does not end in "/" 
RewriteCond %{REQUEST_URI}!/$
# and does not contain a "."
RewriteCond %{REQUEST_URI}!\.
# then add trailing slash and redirect
RewriteRule ^(.*) /$1/ [R=301,L]
#This will redirect a page like domain.com/page to domain.com/page/

I can't get my head around  the syntax used in htacess files, so any examples of what I should type and where is much appreciated Smiley
2 REPLIES 2
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Add trailing slash to URLs via .htaccess?

Could try <a href="http://community.plus.net/forum/index.php/topic,85111.msg705703.html#msg705703">this</a>.
Gabe
jtonline
Grafter
Posts: 83
Thanks: 9
Registered: ‎21-03-2008

Re: Add trailing slash to URLs via .htaccess?

Thanks Gabe, you are indeed a Bright Spark Smiley  Your reply #8 in the Topic you linked to has fixed the issue I was experiencing.
I'm usually quite good at searching for an answer before creating a new topic, but I obviously didn't look hard enough this time.
Regards, Jules.