Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9087959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:48:57+00:00 2026-06-16T21:48:57+00:00

Is it possible to reduce the size of a link (in text form) by

  • 0

Is it possible to reduce the size of a link (in text form) by PHP or JS?

E.g. I might have links like these:

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

The purpose is to find out, if the link can be shortened and still point to the same location. In these examples the first two links can be reduces, because the first points to the root, and the second has parameters that can be omitted.
The third link is then the case, where the parameters can’t be omitted, meaning that it can’t be reduced further than to remove the http://.

So the above links would be reduced like this:

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

Is this possible by PHP or JS?

Note:

www.example.com is not a domain I own or have access to besides through the URL. The links are potentially unknown, and I’m looking for something like an automatic link shortener that can work by getting the URL and nothing else.

Actually I was thinking of something like a linkchecker that could check if the link works before and after the automatic trim, and if it doesn’t then the check will be done again at a less trimmed version of the link. But that seemed like overkill…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:48:58+00:00Added an answer on June 16, 2026 at 9:48 pm

    Since you want to do this automatically, and you don’t know how the parameters change the behaviour, you will have to do this by trial and error: Try to remove parts from an URL, and see if the server responds with a different page.

    In the simplest case this could work somehow like this:

    <?php
        $originalUrl = "http://stackoverflow.com/questions/14135342/reduce-link-url-size";
    
        $originalContent = file_get_contents($originalUrl);
    
        $trimmedUrl = $originalUrl;
    
        while($trimmedUrl) {
            $trialUrl = dirname($trimmedUrl);
            $trialContent = file_get_contents($trialUrl);
            if ($trialContent == $originalContent) {
                $trimmedUrl = $trialUrl;
            } else {
                break;
            }
        }
    
        echo "Shortest equivalent URL: " . $trimmedUrl;
        // output: Shortest equivalent URL: http://stackoverflow.com/questions/14135342
    ?>
    

    For your usage scenario, your code would be a bit more complicated, as you would have to test for each parameter in turn to see if it is necessary. For a starting point, see the parse_url() and parse_str() functions.

    A word of caution: this code is very slow, as it will perform lots of queries to every URL you want to shorten. Also, it will likely fail to shorten many URLs because the server might include stuff like timestamps in the response. This makes the problem very hard, and that’s the reason why companies like google have many engineers that think about stuff like this :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
I am developing an application Android to have the option to reduce the size
Is it possible to reduce the size of your mdf file? So far I
Is it possible to reduce image size while uploading ? Can the size be
Possible Duplicate: Image size got bigger when trying to reduce its size What I
I want reduce the size of my application as much as possible using VisualStudio
I have designed a custom file format / network message to reduce size as
Is it possible to reduce the gap between text, when put in multiple lines
I have a jquery mobile page, containing a listview. Is it possible to reduce
Is it possible to reduce the AlertDialog.Builder title font size and positive button size?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.