Forum Moderators: phranque
1. user visits "domain.com", the url stays at "domain.com" but the content displayed is from "domain.com/path/file.ext"
2. user visits "domain.com/path/file.ext", the url redirects to "domain.com" but the content displayed is from "domain.com/path/file.ext"
Can achieve the first one fine by using a:
RewriteRule ^/$ /path/file.ext [P]
but combining both things is proving very tricky, and keep getting redirect loops, despite trying things with S, N, C, L flags....
Probably just getting the exact combination slightly wrong, but it's driving me crazy and am calling out for your help!
TIA
The solution is that your "no direct access to hidden URL" redirect rule must use a RewriteCond to examine the variable %{THE_REQUEST} to be sure that the URL is the "hidden" one because the client directly-requested it, before you redirect. Otherwise, the "hidden" URL is being internally requested because it has already been rewritten by your other rule, and it must not be redirected or a loop will result as the two rules repeatedly countermand each other.
Using a proxy throughput should not be required; If both paths are in the same domain, you need only the canonical URL redirect for your second case, followed by the an internal rewrite for your first case.
The second case is very similar to the "Redirect 'index.html' to '/' redirects we discuss here often.
Jim