I have a shared hosting account, and there are 2 websites running on it, each with their own domain (example1.com and example2.com). Example1 is the main site and is at the root of the html folder, example2 is inside a folder called ex2. What I want to do is make sure that it is not possible to go to example1.com/ex2/ to use example2, and if this does happen to redirect to example2.com. I have done this with PHP so far:
if (strpos($_SERVER["REQUEST_URI"], "/ex2") !== false)
{
header("Location: http://example2.com");
}
but this is unwieldy as you must include it on every page, and before the html headers. Is there a solution using .htaccess (edit: and if so what is it)?