views:

32

answers:

2

From development to testing to production our website resides in three different environments

  • http: //localhost/version/
  • http: //www.production.com/test/
  • http: //www.production.com/

(see examples of URLs in the following .htaccess snippet)

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^brand/(.+) /products.php?brand=$1 [R,NC]
RewriteRule ^product/(.+) /products.php?model=$1 [R,NC]

How do I capture that first part of the URL and prepend it in the .htaccess file, so that the following URLs all behave the same:

  • http: //localhost/version/product/c20
  • http: //www.production.com/test/product/c20
  • http: //www.production.com/product/c20

I've looked at RewriteCond, but haven't found out how I can use it in this case. Enlighten me, please.

A: 

EDIT: This seems to work:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.+)/(brand|product)/
RewriteRule ^brand/(.+) %1/x.php?brand=$1 [NC]
RewriteCond %{REQUEST_URI} ^(.+)/(brand|product)/
RewriteRule ^product/(.+) %1/x.php?model=$1 [NC]
Max Shawabkeh
This prepends the physical path. Something like this http: //localhost/C:/wamp/www/version/product.php?model=c20
Michael
Edited with a tested solution.
Max Shawabkeh
A: 

You could set that part optional:

RewriteRule ^(version/|test/)?brand/(.+) /$1products.php?brand=$2 [R,NC]
RewriteRule ^(version/|test/)?product/(.+) /$1products.php?model=$2 [R,NC]
Gumbo