Cohvi
Cohvi

Reputation: 11

.htaccess redirect according to referral existence

I need to redirect every url that does not contain ?ref=something, to a fixed html page.

Example:

Action: user navigates to www.domain.com/?ref=somerefcode. Result: stay on the page.

Action: user lands on www.domain.com without ref tag. Result: should be redirected to: www.domain.com/other_page

Thank you very much!

Ronen

Upvotes: 1

Views: 31

Answers (2)

Cohvi
Cohvi

Reputation: 11

Thank you Sergio!

A little correction to fit my question exactly:

RewriteCond %{QUERY_STRING} ^ref=(.*)$
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^ref=(.*)$
RewriteRule ^(.*)$ /other_page [R,L]

Upvotes: 0

Sergio Ivanuzzo
Sergio Ivanuzzo

Reputation: 1922

You can use this rules:

RewriteCond %{QUERY_STRING} ^ref=(.*)$
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} !^/other_page$
RewriteRule ^(.*)$ /other_page [R,L]

Upvotes: 1

Related Questions