I have a domain oldexample.com, and I want to redirect users who visit that domain to newexample.com only when no parameters are given. In the case where parameters are supplied with the domain, it should redirect elsewhere – so, oldexample.com/?id=5 should not redirect to newexample.com, rather I want to redirect it to some internal directory in newexample.com, say to newexample.com/dir/5.
Here’s a summary of how I want the redirects to work:
oldexample.com -> newexample.com
oldexample.com/?id=3 -> newexample.com/dir/3
oldexample.com/index.php?id=6 -> newexample.com/dir/6
So how would I write the RewriteRules in htaccess to get this job done?
Try:
The last rule matches against
/and/index.php. These rules need to be in the htaccess file in youroldexampl.comdocument root.