📜 ⬆️ ⬇️

List of unique website addresses

Suppose you need to make a database table with a list of addresses. Moreover, each site should be mentioned only once. A very common task is to take at least site directories.

The site can be identified by the domain name. If we lived in an ideal world, then in this place my post would have ended. :) But, everything is just beginning here ...

Most sites are accessible (HTML is sent or redirected) at two addresses: example.com and www.example.com . In an almost perfect world :) we would just drop “www.” And score on this problem. But there are some Krivoruk personalities who operate their site only at one address, “only from www.”.
')
The solution is:
  CREATE TABLE test (www CHAR (4), hostname CHAR (64) NOT NULL, UNIQUE (hostname)); 

We separate the “www.” Particle and store it separately, it doesn’t carry any meaning anyway. But now, using a normal domain name, you can make a unique index.

To make a selection on such a table, you can create a mapping (VIEW), or you can simply add a CONCAT statement to SELECT:
  SELECT CONCAT (www, hostname) AS url FROM test; 

ZY “Www.” Is archaism , it is inconvenient and impractical. Let's do without discussions on this topic. ;)
ZYY.Y. And I once wrote about how best to make a redirect for your site from “www.” To the regular version: Tips & Tricks .

Source: https://habr.com/ru/post/26479/


All Articles