Reputation: 1
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
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