.HTACCESS rule to force a specific page to be always shown, irrespective of request.

Soldato
Joined
15 Nov 2003
Posts
14,400
Location
Marlow
I have a subdomain (eg: forum.mysite.com) which resolves to a subfolder on my server. I simply want to set up an .HTACCESS rule so no matter what the url/request that's made (eg: "forum.mysite.com/test.html" or "forum.mysite.com/directory/test.php?x=1"), it always goes to/returns "forum.mysite.com/index.html".

Is there a .htaccess rule I can add to my site to achieve that? Would that be in my main site's .htaccess, or could I add another/new .htaccess into the subfolder where forum.mysite.com points?

Thanks...
 
Last edited:
Thanks....

So taking it only needs to be for the "forum" subdomain?

RewriteCond %{HTTP_HOST} ^forum\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ https://forum.yoursite.com/index.html [R,L]


And that means forum.yoursite.com/dir/x.php?x=1 will still be redirected to forum.yoursite.com/index.html? ie: The path and params will be lost and not included in the redirect?

NOTE: I'll not use the R=301 because from experience it means if you get anything wrong or want to change anything it's cached like the plague and a pain to change?
 
OK... Tried this... And When typing in say forum.yoursite.com/dir/x.php?x=1 I can see the URL in the browser changes to https://forum.yoursite.com/index.html BUT instead of the HTML being returned I get an error shown basically with "ERR_TOO_MANY_REDIRECTS".

If I take those lines back out of the .htaccess file:-
https://forum.yoursite.com/index.html then shows the html fine.
And if I try https://forum.yoursite.com it also resolves to https://forum.yoursite.com/index.html and shows the HTML fine.

But if I put those .htaccess lines back in, those URLs than give an "ERR_TOO_MANY_REDIRECTS" in the browser and the HTML is not shown.

It's like the server is complaining about it?





EDIT:

I tried a new .htaccess filer in the subdomains sub folder, and it seems to work:-
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.html$
RewriteRule $ /index.html [R,L]


So I'm guess that is saying if the URL isn't already index.html then change it to it? That seems fine, and any request to anything seems to land on https://forum.yoursite.com/index.html successfully with no error and shows the HTML fine etc.
 
Last edited:
Back
Top Bottom