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.
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.
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.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
You could try your chances with mod_rewrite. With something like this in the .htaccess:
In theory there is already an env var which does the job:
But I am not sure whether it works... (I never had to use this feature.)