Lokesh Agrawal Lokesh Agrawal - 6 months ago 35
Apache Configuration Question

Selectively redirect to a new domain using apache vhost configuration

This is a followup question on Redirect to a new domain using apache vhost configuration

I want my requests from


to be redirected to


but selectively for some products which are whitelisted.

For example for products :

  1. dell-inspiron-15.

  2. dell-inspiron-16.

  3. dell-inspiron-17

redirect to the new URL but for any other products I want to use the current path itself.

Currently my vhost configuration looks like below. It redirects to someotherdomain for all the products in query parameter.

Listen 12567
NameVirtualHost *:12567

<VirtualHost *:12567>
ServerName somedomain.com
ProxyPreserveHost On

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)product=([^&]+) [NC]
RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]


  1. As asked above, how can I selectively redirect?

  2. Given that my list of whitelisted products is small (maybe some 10-11 items) what is an ideal place to store this whitelisted products and read in vhost and how.

Any leads here is really appreciated.

Answer Source

Since you have a small number of models, you could just list them out, like so:

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-15) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-16) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-17) [NC]
RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]

By default, RewriteCond lines are interpreted with the AND operation between each. So each condition must be TRUE before the RewriteRule is triggered. Here use the OR operator between the lines. As long as one matches, you are ok.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download