通常來講,對於同一服務器上的文件,應該老是使用相對URL,它們更容易輸入,並且在將頁面從本地系統轉移到服務器上時更方便,只要每一個文件的相對位置保持不變,連接就仍然是有效地。服務器
char * url_normalized(char *url) { if (url == NULL) return NULL; /* rtrim url */ int len = strlen(url); while (len && isspace(url[len-1])) len--; url[len] = '\0'; if (len == 0) { free(url); return NULL; } /* remove http(s):// */ if (len > 7 && strncmp(url, "http", 4) == 0) { int vlen = 7; if (url[4] == 's') /* https */ vlen++; len -= vlen; char *tmp = (char *)malloc(len+1); strncpy(tmp, url+vlen, len); tmp[len] = '\0'; free(url); url = tmp; } /* remove '/' at end of url if have */ if (url[len-1] == '/') { url[--len] = '\0'; } if (len > MAX_LINK_LEN) { free(url); return NULL; } return url; }