Jeff
Jeff

Reputation: 1

Simple HTACCESS question to redirect IP to domain name

I'm looking to redirect an IP address to a domain name using HTACCESS. So anytime the IPaddress.com/subdir1/page1.html shows up it'll redirect to domainname.com/subdir1/page1.html

I've tried this with NO LUCK:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Because it ONLY redirects the main IP address to the main domain, not subdirectory ips to subdirectory domains

Thank you Jeff

Upvotes: 0

Views: 1859

Answers (2)

jerdiggity
jerdiggity

Reputation: 3665

Looks like you probably just forgot a ^ and maybe a $ or two... No reason this shouldn't work:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Upvotes: 0

Steve
Steve

Reputation: 1402

Pretty old now, but maybe you meant RewriteCond %{REMOTE_ADDR}

Upvotes: 1

Related Questions