如果URL匹配定义的字符串,使用.htaccess重定向


Redirect if URL match defined strings using .htaccess

我想在单行代码中使用。htaccess重定向一个if URL匹配定义的字符串

如果URL是

  • http://example.com/mobiles/xyz/
  • http://example.com/computers/xyz/
  • http://example.com/books/xyz/

重定向URL
  • http://example.com/comingsoon/

我试过了,但我想定义字符串(例如books, mobile, books)而不是(.*)

 RewriteRule ^(.*)/xyz/?$    upcoming/index.html    [NC,L]

我不知道我是否正确理解了这个问题,但这应该可以解决这个问题:

 RewriteRule ^mobiles|books|computers/xyz/?$ upcoming/index.html [NC,L]

在https://regex101.com/上测试