1

I have to migrate a shop site to another shop system.

The problem I have is that in new shop system, all products name must ended with -detail in the URL.

In today site here is the URL of a product:

domaine.com/shop/category1/productname

In new shop same product will have this URL:

domaine.com/shop/category1/productname-detail

I would like that when using this old URL domaine.com/shop/category1/productname, user will be redirected to right one: domaine.com/shop/category1/productname-detail

can this be done through htaccess without having to define a line for each product (~2500) ?

This shop has also normal URL like domaine.com/contact and I don't want to add -detail for those URL. Only when calling a product into a shop category.

Croises
  • 18,570
  • 4
  • 30
  • 47
  • Yes, it should be possible with a [negating regex](http://stackoverflow.com/questions/977251/regular-expressions-and-negating-a-whole-character-group) that matches anything that doesn't have `-detail` in the end. Have you tried to do anything yet, or are you expecting us to do your work for you? – h2ooooooo Dec 28 '14 at 13:57
  • Thanks for your quick answer. Yes I have tried to find a solution by searching into this forum but I couldn't find any solution suiting to my need. I will try to check what negating regex is. – Jean Charle Dec 28 '14 at 14:05

1 Answers1

2

You can do this using mod_rewrite. Make sure mod_rewrite module is loaded in your main config file. Then put the in your .htaccess. The condition makes sure the url does not end with -detail. Then an url with shop, followed by 2 other path parts is redirected to the same url with -detail appended.

RewriteEngine on

RewriteCond %{REQUEST_URI} !-detail$
RewriteRule ^shop/[^/]+/[^/]+/?$ %{REQUEST_URI}-detail [R,L]

After testing this rule and making sure it works correctly, replace the R flag with R=301 to make the redirect permanent.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
  • @JeanCharle Please note that as the person that asked the question, you can mark answers as the accepted answer. See [this help-page for more information](http://stackoverflow.com/help/accepted-answer). – Sumurai8 Dec 28 '14 at 14:49