homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Forward slash on URL
Need to redirect to include forward slash on the end

10+ Year Member

Msg#: 3024855 posted 8:38 pm on Jul 27, 2006 (gmt 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?




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

Msg#: 3024855 posted 4:43 am on Jul 28, 2006 (gmt 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]



10+ Year Member

Msg#: 3024855 posted 1:09 pm on Jul 28, 2006 (gmt 0)

Excellent - that works great - thanks very much!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved