Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a simple hosting account, and the folder structure is as follows:

/ (web root)

Due to some server migrations going on, I needed to have a real domain pointed at the web root, let's say with or without the www

I need an .htaccess file that forces all access to index.php page when you access For example, you would be unable to render domain1's website by loading and instead be forced to go to

I have tried writing it on my own, but keep blowing up the server with bad redirects. Any help?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Your own redirects were most likely recursively redirecting to the index.php. You need to block the rule for that script, so it isn't run on that page request, e.g.:

RewriteCond %{HTTP_HOST} ^(www\.)?domain0\.com$
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^ /index.php [L,R]

This should be put above any conflicting RewriteCond/Rule's, so they wont interfere with the redirection.

Any .htaccess files in subdirectories will by default remove this rule and not do the redirect. To fix them, you must add either the rule again to them, or set them to inherit from parent .htaccess files, e.g.:

RewriteOptions inherit
share|improve this answer
This works for most requests, but if I make a request to a known file http://(www.) it will render domain1's index page. How can I prevent this to redirect everything? – Urda Dec 19 '10 at 20:41
Are there any other RewriteRules in the .htaccess? I'm guessing there is another rule that is interfering. To get the correct fix, I'd need to see all of it. – Andy Dec 19 '10 at 20:54
If you place the rule above the others, it should solve the problem. – Andy Dec 19 '10 at 20:56
I have only these rules (plus rewrite on) in the .htaccess file. It is in the root directory / – Urda Dec 19 '10 at 20:57
Do these websites do some automatic rewriting of their own, e.g. going to serves /domain1/?. If so, there is probably a RewriteRule inside the apache config itself that is doing this. Your only solution then would be to add the conds/rule to each domain's path as well. – Andy Dec 19 '10 at 21:02

Your Answer


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.