Welcome to WebmasterWorld Guest from 50.19.53.104

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Forward slash on URL

Need to redirect to include forward slash on the end

     

dramstore

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

10+ Year Member



Hi

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?

Thanks

jdMorgan

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

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



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]

Jim

dramstore

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

10+ Year Member



Excellent - that works great - thanks very much!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month