【发布时间】:2012-12-17 14:30:52
【问题描述】:
是否可以通过 PHP 或 JS 减小链接(文本形式)的大小?
例如我可能有这样的链接:
http://www.example.com/index.html <- Redirects to the root
http://www.example.com/folder1/page.html?start=true <- Redirects to page.html
http://www.example.com/folder1/page.html?start=false <- Redirects to page.html?start=false
目的是找出链接是否可以缩短并且仍然指向相同的位置。在这些示例中,前两个链接可以归约,因为第一个指向根,第二个具有可以省略的参数。
那么第三个链接就是这种情况,参数不能省略,也就是说除了去掉http://之外,不能再进一步减少了。
所以上面的链接会这样减少:
Before: http://www.example.com/index.html
After: www.example.com
Before: http://www.example.com/folder1/page.html?start=true
After: www.example.com/folder1/page.html
Before: http://www.example.com/folder1/page.html?start=false
After: www.example.com/folder1/page.html?start=false
这可以通过 PHP 还是 JS 实现?
注意:
www.example.com 不是我拥有或通过 URL 访问的域。这些链接可能是未知的,我正在寻找一种类似于自动链接缩短器的东西,它可以通过获取 URL 来工作。
实际上,我正在考虑类似链接检查器之类的东西,它可以检查链接在自动修剪之前和之后是否有效,如果没有,那么将在链接的修剪较少的版本中再次进行检查。但这似乎有点矫枉过正......
【问题讨论】:
-
是 www.example.com 您的网站(即由您控制)还是 www.example.com 的任何网站?
-
如果你有服务器访问权限,我建议.htaccess
RedirectRule's -
不,它们不是我的域。请参阅上面添加的注释。
标签: php javascript url hyperlink reduce