TomJones999 TomJones999 - 1 month ago 5
Apache Configuration Question

.htaccess regex - "keyword" style redirects - syntax?

Problem: inbound outdated links to products that have been discontinued.
Challenge: many variations with additional keywords, subcategories, etc.

Examples:


  • /somecategory/cool-widget-OLDNAME

  • /special_sale_on_OLDNAME_items

  • /category/subcat/subsubcat/morestuff/weird_keywords_OLDNAME



Needed solution: something that will catch the keyword "OLDNAME" *regardless of what it's surrounded by, and redirect to a specific page.

E.g. "RewriteRule ??????? OLDNAME ?????? http://www.example.com/newpage [L,NC,R=301]

The bold part is what I need help with.

Thanks in advance!

Answer

Try

RewriteRule  ^.*(OLDNAME|ANOTHEROLDNAME).*$ http://www.example.com/discontinued [L,NC,R=301]

it lookups any given word at any position in the given url.