RewriteEngine On
RewriteCond %{HTTP_REFERER} \?.*\bbikes=1\b [NC]
RewriteRule ^product-configurator$ /bikes-configurator [QSD,R=307[R=307,L]
If this is intended to work for "any traffic" (as suggested in a comment), not just requests for /product-configurator
then change the RewriteRule
pattern to something like ^
instead. The QSD
flag is then required in order to remove the query string from the redirected request, to avoid a redirect loop.
However, it's not clear why you would need to "redirect" the request since this is all happening on the same server. You could potentially internally rewrite the request instead (no external redirect, no second request, quicker and more efficient all round). However, /product-configurator
and /bikes-configurator
require further routing to get to your PHP script - so "rewriting" to /bikes-configurator
is not correct.
UPDATE: In that case, it would be
/product-configurator.php
Assuming you are just using extensionless URLs and the underlying file that handles the request is simply /bikes-configurator.php
then you can perhaps implement an internal rewrite instead.
For example, instead of the above, this would be written as:
RewriteCond %{HTTP_REFERER} \?.*\bbikes=1\b [NC]
RewriteRule ^product-configurator$ /bikes-configurator.php [L]
The URL in the address bar stays as /product-configurator
, but the request is internally rewritten (note the absence of the R
flag) to /bikes-configurator.php
when bikes=1
is included in the query string of the HTTP Referer
. There is no external redirect.
This may also be solvable directly in your PHP script - no additional redirect/rewrite in .htaccess
required. (Although from your recent comments, it looks like the request /bike-configurator
is simply extensionless and the request maps to the PHP file /bike-configurator.php
? The logic that tests the HTTP_REFERER would need to be in /product-configurator.php
- you then make the necessary PHP calls to pass control to /bike-configurator.php
if the condition is met - but exactly how you do this depends on the structure of your app.)