Home > Blockchain >  htaccess redirect only specific page, not subpages
htaccess redirect only specific page, not subpages

Time:12-10

I have a website with following url structure:

  • www.example.com/products
  • www.example.com/products/productA
  • www.example.com/products/productB

I need to redirect www.example.com/products to www.example.com but www.example.com/products/productA and productB should still be available.

Does anyone have an idea?

CodePudding user response:

At the top of your .htaccess file, using mod_rewrite:

RewriteRule ^products$ / [R=302,L]

I've used mod_rewrite here, as opposed to a mod_alias RedirectMatch directive since I assume you are already using mod_rewrite later in the file to rewrite your URLs. It is preferable not to mix redirects/rewrites from both modules.

Reference:

  • Related