views:

31

answers:

1

I have the following list of URLs to rewrite:

1 write url
/products/client/

send to
/basedir/system/index.php?client=cliente

2 write url
/product/client/index.php

send to
/basedir/system/index.php?client=cliente

3 write url
/products/client/image/dir2/myimage.jpg

send to
/basedir/system/image/client/dir2/myimage.jpg

4 write url
/products/client/image/dir2/more_x_dir/other.img

send to
/basedir/system/image/client/dir2/more_x_dir/other.img

With these rules I have more or less solved the points 1 and 2:

 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteRule ^product/([a-zA-Z]+)$ /basedir/system/index.php?client=base=$1 [L,QSA]
 RewriteRule ^product/([a-zA-Z]+)/$ /basedir/system/index.php?client=base=$1 [L,QSA]
 RewriteRule ^product/([a-zA-Z]+)/(.*)$ /basedir/system/index.php?client=$1 [L,QSA]

My problem is in cases 3 and 4 when I have files with css / image's / js. and also when I have many directories, it may be that in the case of many directories have to make a rule for everyone, but I do not know how.

thank you very much

Edit

my solution based on the answer accepted:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^product/([a-zA-Z]+)/(.*)\.(gif|jpg|ico|css|js|txt|zip|xls|doc)$ /basedir/system/$2.$3 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/index.php$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/(.*)$ /basedir/system/$2?database=$1 [L,QSA]
A: 

I believe that you want to do something like the following, based on your description (I'm still a little confused about the rules that you currently have). I also make the assumption that you had folders named image, css, and js for each client.

RewriteEngine On

# Rewrite images/css/js to their real files
RewriteRule ^products/([^/]+)/(image|css|js)/(.*)$ /basedir/system/$2/$1/$3 [L]

# Rewrite everything else to the index.php script
RewriteRule ^products/([^/]+)(/.+)?$ /basedir/system/index.php?client=$1 [QSA,L]
Tim Stone