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.

link|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
feedback

4 Answers

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.

link|improve this answer
feedback

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]
link|improve this answer
feedback

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

link|improve this answer
feedback

the tutorial worked perfect for me.. look at the trailing slash part.. that is what fixed my problem

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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