Adding a trailing slash
3 posts
• Page 1 of 1
Adding a trailing slash
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:
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.
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.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Adding a trailing slash
Hi,
it does make sense. Try to use this rule on top of your config file:
Regards
Andrew
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
Re: Adding a trailing slash
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:
Many thanks.
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.
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests