Andy Chuo
Andy Chuo

Reputation: 127

User mod_rewrite to fake subdirectory

My current web root directory has:

/product-a.php

/product-b.php

How to I rewrite it so that:

  1. it auto detects and displays all URL ending with /product-a.php on my site to become /products/product-a

  2. when clicking onto these links /products/product-a it send back requests as /product-a.php

Thanks for your help!

Andy

Upvotes: 2

Views: 107

Answers (1)

anubhava
anubhava

Reputation: 785226

nable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^products/([^/]+)/?$ /$1.php [L,NC]

Upvotes: 1

Related Questions