redirect ip to dmain name

Banisaeed

Verified User
Joined
Sep 23, 2015
Messages
34
Hello

i can't redirect ip to domain name !
guides on the Internet was useless
How do I do this?
 
Hello,

Kindly provide details on which exactly solutions your tried and what exactly did not work out? Nobody wants to play a guess game, suggesting solutions which you probably already tried.
 
Hello,

Kindly provide details on which exactly solutions your tried and what exactly did not work out? Nobody wants to play a guess game, suggesting solutions which you probably already tried.

i tried these codes but not worked:

in htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ https://domainname.com/$1 [L,R=301]

and

RewriteEngine On
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?domain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
 
Last edited:
And you replaced fake IPs and domain names with your real IPs and domains?

If yes, then I believe you added the file into a wrong location.

For server IP it should be /var/www/html/.htaccess

For shared IPs it should be /home/admin/domains/sharedip/public_html/.htaccess

- admin might need to be replaced by another reseller, which you use there.

And only for private/dedicated IPs it should be under /home/bob/domains/example.net/public_html/.htaccess

- bob - a fake username to be replaced by a real username.
- example.net - a fake domainname to be replaced by a real domain name.


p.s. I did not validate your mod_rewrite rules, and I assume they are fine. Anyway it's up to you to verify they work under a correct location.
 
And you replaced fake IPs and domain names with your real IPs and domains?

If yes, then I believe you added the file into a wrong location.

For server IP it should be /var/www/html/.htaccess

For shared IPs it should be /home/admin/domains/sharedip/public_html/.htaccess

- admin might need to be replaced by another reseller, which you use there.

And only for private/dedicated IPs it should be under /home/bob/domains/example.net/public_html/.htaccess

- bob - a fake username to be replaced by a real username.
- example.net - a fake domainname to be replaced by a real domain name.


p.s. I did not validate your mod_rewrite rules, and I assume they are fine. Anyway it's up to you to verify they work under a correct location.

yes, with real IP and domain
That was the path: /home/admin/domains/sharedip/public_html/.htaccess , I've deleted it.
And now I put the following code in this path: /var/www/html/.htaccess via ssh

RewriteEngine On
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?domain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

And the problem was solved
 
Last edited:
Here is how I do this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?MYDOMAIN\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.MYDOMAIN.com/$1 [L,R=301]
 
Back
Top