0

Whenever user comes in example.com how to redirect them to example.com/home

Note: The current routing/URL paths should work after adding this condition/rule

For example:

  • example.com/about-us -> no redirect
  • example.com/contact -> no redirect
  • example.com/admin -> no redirect
  • example.com or example.com/ -> Need to redirect to example.com/home

How can be this done with .htaccess rule?

1

It looks like you just need to redirect a specific URL; the document root. At the top of your .htaccess file try the following mod_rewrite directive:

RewriteRule ^$ /home [R=302,L]

I assume you are already using mod_rewrite, as otherwise you are unlikely to have URLs like /about-us and /contact, etc.

Note the above is a 302 (temporary) redirect.


example.com or example.com/ -> Need to redirect to example.com/home

These are the same URL. There is always a trailing slash after the hostname, even if you don't see it in the browser's address bar. See the following question for reference:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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