3

I have htacess code that redirects

http://website.com:352/pictures/1 to another page. 

I would like to prevent this redirect if the request is in iframe src. Is this possible?

<iframe src="http://website.com:352/pictures/1" style="border: none; width:100%; height:1100px;"></iframe>
Sam Kingston
  • 817
  • 1
  • 10
  • 19
  • 1
    The server doesn't care if its an iframe or not, htaccess is sending it on its way. If you find a solution later down the line while being able to keep the code in the htaccess, please answer your own question as this sounds like a neat one – Jesse Sep 26 '15 at 06:52
  • Somewhat relevant to your need, but as source says, not reliable -> http://stackoverflow.com/questions/4500939/htaccess-redirect-unless-in-iframe – Jesse Sep 26 '15 at 06:53
  • 1
    I just read what you linked for referer. How could it be applied in this case? – Sam Kingston Sep 26 '15 at 06:54
  • The Referrer is an absolutely unreliable variable. Forget that it exists. – CBroe Sep 26 '15 at 09:33
  • This would be easiest to solve, if you appended a query string to your iframe src, such as `http://website.com:352/pictures/1?noredirect`, and then checked for the existence of that value in the query string before doing the rewriting, via a `RewriteCond` before your RewriteRule. – CBroe Sep 26 '15 at 09:35
  • Any way how this could be done, appending the query string that is. – Sam Kingston Sep 26 '15 at 19:25

1 Answers1

0

You can do that by adding a request header to the request and then check in your htaccess file for that header and make the redirect if the header does not exist.

However, to add a request header to the iframe, you need to make a workaround by creating AJAX request that and appending the results to the iframe You can check this answer that explains how to do that: How to set custom http headers when changing iframe src?

Community
  • 1
  • 1
Dola
  • 1,483
  • 11
  • 16