Adding a trailing slash

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 24 Jan 2014, 10:09

Adding a trailing slash

24 Jan 2014, 11:40

Hi,

Firstly, I apologise, I know this question has been asked several times but in each example I've read the code is different to my own rewrite rule and I'm finding it hard to know what to do.

I have a simple URL ReWrite that looks like this:

Code: Select all
RewriteRule ^product/(\d+)/([^/]+)/?$ details.asp?prodId=$1&name=$2 [NC,L]


This lets me use a url like: mysite.com/product/2/my_product/ and map it to: mysite.com/details.asp?prodId=2&name=my_product

This works fine, however through my own fault some of the links on my site (and therefore in search engine indexes) have a trailing slash and some don't:

mysite.com/product/2/my_product/
mysite.com/product/2/my_product

both url's work and bring up the correct page by I'm getting duplicate content issues.

I have fixed the site so all url's now have the trailing slashes but Google, etc still have indexed the url's without trailing slashes.

Can I add a rule that will add a trailing slash if one is missing and 301 update at the same time. So if:

mysite.com/product/2/my_product

...was called it would 301 redirect to:

mysite.com/product/2/my_product/

I hope that makes sense and someone can help.

Many thanks.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding a trailing slash

24 Jan 2014, 12:15

Hi,

it does make sense. Try to use this rule on top of your config file:

Code: Select all
RewriteRule ^(product/\d+/[^/]+)$ /$1/ [NC,R=301,L]


Regards
Andrew

User avatar
Posts: 2
Joined: 24 Jan 2014, 10:09

Re: Adding a trailing slash

24 Jan 2014, 13:26

Hi Andrew,

Thanks for your super speedy reply - I've added your rule just above the existing rewrite (it that the position you meant?) and it works a treat:

Code: Select all
RewriteRule ^(product/\d+/[^/]+)$ /$1/ [NC,R=301,L] 
RewriteRule ^product/(\d+)/([^/]+)/?$ details.asp?prodId=$1&name=$2 [NC,L]


Many thanks.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests