2

How to redirect requests to another folder using .htaccess?

I have my root directory and my website looks into that directory. I want it to look in the /subdirectory/ instead. I can't modify the server config.

0

1 Answer 1

1

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ subdirectory [L]

If you want an external redirect, set the R flag there as well:

RewriteRule ^$ /subdirectory [L,R=301]
2
  • OK, it redirects, but I see www.myurl.com/subdirectory how can I hide subdirectory from URL?
    – Andrew
    Commented Oct 23, 2012 at 1:05
  • Check this answer out stackoverflow.com/a/10427485/804087
    – Anagio
    Commented Oct 23, 2012 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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