Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to redirect this:

http://www.site.com/xyz

To

http://www.site.com/

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
add comment

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.

1 Answer

Do you want the rewrite to happen even if site.com/xyz 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
add comment

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