How to .htaccess redirect with or without www. (respecting the www.)

Discussion in 'Apache' started by Pros, Jan 24, 2011.

  1. #1
    Edit: I found the answer, thank you. If you're curious (or coming from Google), you can read on, the answer is at the bottom of the post. If you have a better way of doing it, feel free to post it!

    Hi,

    I want to redirect everything from the main page of my site to a directory, respecting the "www."

    So if they don't type www., it doesn't force it, and if they do type www., it doesn't remove it.

    So for example,

    www.mydomain.com goes to www.mydomain.com/dir

    and

    mydomain.com goes to mydomain.com/dir


    Thank you.

    Edit (answer):

    RedirectMatch permanent ^/$ /dir
    Code (markup):

     
    Last edited: Jan 24, 2011
    Pros, Jan 24, 2011 IP