TomJones999 TomJones999 - 1 year ago 124
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.


  • /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 ?????? [L,NC,R=301]

The bold part is what I need help with.

Thanks in advance!

Answer Source


RewriteRule  ^.*(OLDNAME|ANOTHEROLDNAME).*$ [L,NC,R=301]

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download