This is a followup question on Redirect to a new domain using apache vhost configuration
I want my requests from
somedomain.com/loadproduct?product=dell-inspiron-15
to be redirected to
someotherdomain.com/dell-inspiron-15
but selectively for some products which are whitelisted.
For example for products :
- dell-inspiron-15.
- dell-inspiron-16.
- 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]
</VirtualHost>
Questions:
- As asked above, how can I selectively redirect?
- 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.
Since you have a small number of models, you could just list them out, like so:
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.