0

I'd like to stop Apache from applying rules if the user has been redirected before:

Example:

Redirect 301 /foo/bar.php https://example.org/foo/bar

## Don't apply this if the user has been redirected using the 301 above
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ index.php?foo=$1 <-- I don't want to add the parameters here, if the user has been redirected

So far I was thinking about checking a status using SetEnvIf, but this does not even match here:

SetEnvIf Referer "^$" local_referal=1

RewriteCond %{ENV:local_referral} 1
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
SPQRInc
  • 162
  • 4
  • 23
  • 64
  • 1
    So now you redirected from `/foo/bar.php` to `/foo/bar`, what is supposed to happen next? If you don’t want to rewrite this to `index.php?foo=$1` – then what else? Do you have other rewriting that makes your server handle `/foo/bar` then? Or is that supposed to happen based on MultiViews, and serve `/foo/bar.php`? – CBroe Feb 25 '21 at 08:11
  • 1
    There is no reliable way to do this, if you don’t want to add any info to the URL itself. The referrer is unreliable, might not be send at all, and if you tried to set a cookie together with the redirect, to have _something_ that you can identify this request as being “special” by, there’s also a high chance clients might block this. – CBroe Feb 25 '21 at 08:12

0 Answers0