Forum Moderators: phranque

Message Too Old, No Replies

Apache rewrite rule from IP to Domain

redirect traffic from IP to fully qualified domain name with 301 redirect

         

newskumar

8:06 pm on Sep 8, 2011 (gmt 0)

10+ Year Member



Please refer : [webmasterworld.com...]

RewriteCond %{HTTP_HOST} ^123\.234\.345\.456(.*)
RewriteRule ^/(.*)$ [domainname.com...] [R=301,L]

In the rewrite rule “^/(.*)$” helps to prevent the extra trailing slash right after the domain name.
Ex:
If the rule is “(.*)” then apache redirect to www.domainname.com//
If the rule is “^/(.*)$” then Apache redirects to www.domainname.com

phranque

4:59 am on Sep 9, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, newskumar!

are you doing this in the server config or per-directory config?
(httpd.conf vs .htaccess)

g1smd

7:52 am on Sep 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



^123\.234\.345\.456(.*)


What is the trailing (.*) for?

It will capture the port number (if there is one in the request), but you're not using it for anything.

Remove the (.*) completely.

Use example.com in the forum to stop URL auto-linking.

The canonical URL for the root of a domain should end in a single tailing slash.