Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Forward slash on URL

Need to redirect to include forward slash on the end

8:38 pm on Jul 27, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 23, 2003
votes: 0


Wonder is anyone can help me with this, I know its a common problem (seen it mentioned here a few times) and have searched many similar posts but I don't know enough about it to apply to my problem, I spent most of yesterday working on this, driving me mad now!

I have a .htaccess file which creates a clean url like this:

RewriteRule ^widgetdetails/([^/]+)/([^/]+)/?$ wdgetdetails.php?state=$1&color=$2 [L]

So my url:
site.com/wigitdetails/NC/Red/ sends params NC and Red to widgetdetails.php

This works fine, only problem is the URL:

site.com/wigitdetails/NC/Red (note lack of forward slash on the end) also works - duplicate page!.

What I want to do is 301 redirect the latter to have a slash on the end (or any work around if thats not possible).

I have tried many combinations, such as having an extra line of:

RewriteRule ^widgetdetails/([^/]+)/([^/]+)?$ widgetdetails/$1/$2/ R=301,N] (many combinations of various N,R,L,etc flags and position in the .htaccess file) but it either doesn't work or produces 'page not found'.

Anyone any ideas?


4:43 am on July 28, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

This rule, placed before your existing rule, will redirect widgetdetails URLs with a missing trailing slash:

RewriteRule ^widgetdetails/([^/]+)/([^/]+)$ http://www.example.com/widgetdetails/$1/$2/ [R=301,L]

You can then remove the traling question mark in your existing rule, making the trailing slash non-optional:

RewriteRule ^widgetdetails/([^/]+)/([^/]+[b])/$[/b] /widgetdetails.php?state=$1&color=$2 [L]


1:09 pm on July 28, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 23, 2003
votes: 0

Excellent - that works great - thanks very much!