Htaccess 301 redirect - HELP!

Discussion in 'Apache' started by TODMovies, Mar 23, 2011.

  1. #1
    Hi there.

    I have a website that has been indexed by Google by ip address. I have managed to redirect the ip address to the domain name using this code.

    RewriteCond %{HTTP_HOST} ^mydomain\.com [OR]
    RewriteCond %{HTTP_HOST} ^12\.131\.34\.247
    RewriteRule (.*) http://www.mydomain.com/$1 [L,R=301]

    This works fine for the home page but I need to redirect the inner pages also.

    For e.g.

    I need to redirect:

    http://12.131.34.247/contact-us/

    to

    http://www.mydomain.com/contact-us

    Can someone pls help!
     
    TODMovies, Mar 23, 2011 IP
  2. manojsamtani

    manojsamtani Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    You can use the following:

    RewriteCond %{HTTP_HOST} ^mydomain\.com [OR]
    RewriteCond %{HTTP_HOST} ^12\.131\.34\.247
    RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [L,R=301]

    The change is just

    RewriteRule ^/(.*)

    instead of RewriteRule (.*)$

    Please try and let me know too!!!

    Thanks,
    Manoj Kumar
     
    manojsamtani, Mar 24, 2011 IP