Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to redirect this:


Basically i want to redirect to the root domain if a user types anything else after the first slash of my domain name like /xyz or anything else should be redirected or rewritten as the root URL in the browser. Can anybody help? Thanks for your help!

(* This should be only for the first time like when a new user comes to visit my page, because once the page loads for the first time i do not want any re directions as i have different directories, and related webpages. Otherwise my visitor will only see landing page. )

share|improve this question

closed as not a real question by Brent Pabst, mdpc, Magellan, EEAA, rnxrx Oct 27 '12 at 5:54

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Do you want the rewrite to happen even if is a valid URL?

In that case I think you should redirect with your PHP/whatever you're running based on a cookie instead of redirecting everything. (Since I don't think it's possible to redirect/not redirect based on previous visits with only mod_rewrite)

If you only want to redirect invalid URLs you can use the ErrorDocument-directive, or mod_rewrite with the -f flag to RewriteRule.

share|improve this answer

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