Yes, you can construct a condition to do this (although it sounds a little bit weird, but hey) ...
To check that the user "clicked" a link on a page that links to the same page... in other words, whether the requested host + URL-path is a subset of the HTTP Referer request header, then you can do something like the following using a mod_rewrite condition:
RewriteCond %{HTTP_REFERER}@@%{HTTP_HOST}%{REQUEST_URI} ^https?://([a-z.-]+/[^?]*)(?:.*)@@\1$
The @@
is just a character sequence that doesn't occur in the URL and acts as a delimiter between the two parts we are trying to match.
The CondPattern (regex) uses a backreference (\1
) to check that the captured subgroup in the Referer pattern matches HTTP_HOST
+ REQUEST_URI
.
If your site is only HTTPS then you can remove the ?
in ^https?://
.
Note that this explicitly ignores any query string that might be on the HTTP_REFERER, only the URL-path and hostname is checked.
Just need to add the obligatory note regarding the HTTP Referer request header... it is not 100% reliable. The user-agent may not send the Referer header when one is expected and it is easily faked if a user is inclined to do so.