Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Our domain.com/app/index.php is loading domain.com/blog in an iframe.

So my redirect rules should be like;

- domain.com/              => /app/index.php
- domain.com/blog(.*)      => /app/index.php?(.*)

Second rule is there because if someone wants to go to blog directly, we run our app first and put the blog in iframe, and append incoming querystring to iframe src tag so that it opens not on it's homepage but on requested URL.

Problem is, since I am redirecting everything on my first rule, iframe ends up in infinite loop. It tries to putself inside another iframe within it's own iframe endlessly.

Is there a way to assign an Env var so that if redirection is made, it's not repeated ?

Or to clearly address the problem, I never want blog to open without the app. How should my htaccess be ?

Thanks, D

ps: we want to do it on htaccess, since php+js redirections are inefficient and ugly.

share|improve this question
    
none of these answers is setting Env var, to kill the loop. And I still couldn't figure it out myself. –  Devrim Dec 11 '09 at 8:43

4 Answers 4

You could investigate the RewriteCond directive for conditionally applying the RewriteRule. However this shouldn't be strictly necessary if your RewriteRule explicitly matches the beginning and end of the expected URL to redirect e.g.


RewriteRule ^/$ /app/index.php [L]

Note that the redirect can be internal or external. If you explicitly provide the [R] flag to your RewriteRule then the browser will be informed of the new URL to fetch. Otherwise Apache will attempt to fetch the rewritten rule internally without informing the browser of the actual URL fetched.

Lastly, you can use mod_rewrite directives (RewriteEngine, RewriteCond, RewriteRule) in your .htaccess file.

share|improve this answer

I published a tutorial about avoiding infinite loops which you might find useful. There is a big problem when creating rewrite rules for URLs without a trailing slash. I hope it gives you insight. -scout

share|improve this answer

You could try your chances with mod_rewrite. With something like this in the .htaccess:

RewriteEngine On

RewriteRule /blog/(.*) /app/index.php?$1 [R]
RewriteRule ^index.php$ /app/index.php [R]
share|improve this answer

In theory there is already an env var which does the job:

RewriteCond     %{ENV:REDIRECT_STATUS}          200
RewriteRule     .*              -               [L]

But I am not sure whether it works... (I never had to use this feature.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.