1

How do I redirect IP to actual domain? For example:

123.45.678.901 to www.example.com

and all subfolders and subpages like

123.45.678.901/all-pages to www.example.com/all-pages

Also, my SearchConsole also recognizes "top linking sites" for the same IP but in this manner:

IP 123.45.678 ---------------------------- 38,132 LINKS

IP 123.45.678.901 ------------------------- 3,617 LINKS

So I probably should redirect 123.45.678 as well. Is that possible and how?

One more thing - IP opens in HTTP and domain opens in HTTPS protocol.

paranoic
  • 33
  • 7
  • Your question is very unclear, you will need to edit to to enhance the information... What you need to explain: how are those ip addresses involved, do you get http requests to those addresses or from those addresses? If to and they are actually controlled by you, then do you really get requests to the address as host name? And about those "linking sites", those are sites to carry links to your sites, how do you want to redirect those? Or do you mean redirect requests from clients using references from those adresses? We cannot somehow magically guess all that. You will need to tell us . – arkascha Feb 22 '20 at 08:43
  • Ok @arkascha, so thanks for your answer but i think you got it more complicated than it is. I will try to be as clear as possible. My website opens on my domain www.example.com as well as on IP address 123.45.678.901. i can open both of them which make them duplicate pages. If i open www.example.com/any-other-page-or-subfolder.html the same page can be opened with IP 123.45.678.901/any-other-page-or-subfolder.html. My problem is that Google SE recognized both domain and IP which very bad because they maake duplicate pages SO what i need to do is redirect all links with IP to open as domain – paranoic Feb 22 '20 at 09:26
  • 1
    Do you have any directives in your `.htaccess` file currently? – MrWhite Feb 22 '20 at 16:59
  • @MrWhite yes ther is number of redirects in .htaccess file – paranoic Feb 23 '20 at 01:27

2 Answers2

1

Your comment to your question indicates that this is much easier than the description in the question itself indicates... The following should point you into the right direction, though you may have to tweak it for your situation. It odes not implement any specific address (which might change) but instead redirects every requested host name (so also ip addresses) that do not match your desired host name. In case you want to add exceptions you can di that using RewriteCond directives, for example in case your http server serves multiple host names / domains.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [QSA,R=301]

It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...

This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess"). Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • I dont know how to tweak it that is why i wrote this thread. Thank you fro detailed information but those are not a solution to my problem – paranoic Feb 22 '20 at 16:11
  • 1
    Again the issue: you give far too few details. How do you expect me to answer to "not a solution"? What does that mean? What happens if you use that rule? How did you apply it? Is there a wrong redirection? None? Do you get an error? Which? What do you see in your http server's error log file? – arkascha Feb 22 '20 at 16:28
  • You'll probably want an `L` (or `END`) flag to prevent any directives that follow being processed. And this should go at the top of the `.htaccess` file. – MrWhite Feb 22 '20 at 17:01
  • @arkascha what clearer explanation do you want then redirecting IP to real domain. it is like redirecting old domain to the new domain only IP. i mean, you are going to far with this discussion and there is no use of it. anyone who knows .htaccess knows solution/code for this problem without any discussion. so please let someone else who knows something about it to give his opinion. Thanks – paranoic Feb 23 '20 at 01:03
  • Sorry, but I actually asked very specific questions in my comment above. Which you do not answer to. I am trying to help, you act annoyed. I ask those questions since the rule I posted vertainly _does_ redirect a request directly to the IP address to the host name you specified. So if you then just state that this is "not a solution", don't you think yourself that there is little others can do then to help you? It is _your_ desire to get help. In my eyes it is then a pretty strange behavior to get annoyed when being asked specific, solution focused questions. – arkascha Feb 23 '20 at 11:48
0

Here is the solution to this kind of problem

In the .htaccess file put next code:

RewriteBase /
RewriteCond %{HTTP_HOST} ^123\.45\.678\.901$
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

So if you have a URL wit IP like

123.45.678.901/all/other/pages/

after implementing this code all pages are going to be redirected to

www.example.com/all/other/pages/

I hope i could help anyone because this is one of very important factors which may ruin your SEO.

paranoic
  • 33
  • 7