More than 1 RewriteRule for one RewriteCond set

Using mod_rewrite to handle various content issues

More than 1 RewriteRule for one RewriteCond set

Postby paha » Tue Nov 28, 2006 1:25 am

Do you know any tricks to use several RewriteRule for one RewriteCond set?

Assume we have the following:
*************************
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^<referrer_1_url>$ [NC]
RewriteCond %{HTTP_REFERER} ^<referrer_2_url>$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^<referrer_3_url>$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^<referrer_4_url>$ [NC,OR]
...
RewriteCond %{HTTP_REFERER} ^<referrer_N_url>$ [NC]

RewriteRule download/file1_setup\.(exe|zip)$ <file1 path> [R]
...
RewriteRule download/file2_setup\.(exe|zip)$ <file2 path> [R]
RewriteRule download/file3_setup\.(exe|zip)$ <file3 path> [R,L]
*************************
The RewriteCond block is used only for the first RewriteRule (which is right after this block), and as you can see, the RewriteCond block is too big to repeat it for each RewriteRule.

As an idea: maybe by setting a specific ENV variable which can then be used to identify that the block of RewriteCond conditions was met?

Are there any other approaches?
paha
 
Posts: 2
Joined: Tue Nov 28, 2006 1:11 am

Postby richardk » Tue Nov 28, 2006 9:16 am

You could probably just simplify both sets
Code: Select all
RewriteCond %{HTTP_HOST} ^http://(www\.)?(domain\.com|domain\.net|example\.com|etc.)(/.*)?$ [NC]


Code: Select all
RewriteRule download/(fileone|filetwo|filethree)\.(exe|zip)$ /some/other/path/$2/$1.dat [R,L]


With a specific ENV variable:
Code: Select all
Options +FollowSymLinks

RewriteCond %{ENV:REF_OK} ^$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?(domain\.com|domain\.net)(/.*)?$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^<referrer_2_url>$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^<referrer_3_url>$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^<referrer_4_url>$ [NC]
RewriteRule .* %{REQUEST_URI} [E:REF_OK=TRUE]

RewriteCond %{ENV:REF_OK} ^TRUE$
RewriteRule ^download/file1_setup\.(exe|zip)$ <file3 path> [R,L]

RewriteCond %{ENV:REF_OK} ^TRUE$
RewriteRule ^download/file2_setup\.(exe|zip)$ <file2 path> [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 7 guests

cron