Skip to content

Script to find out redirect history and error codes - useful tool to test redirects after applying them

Notifications You must be signed in to change notification settings

Ashley-Edge/URL_Redirect_Checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

URL Redirect Checker

  • This script checks a list of URLs and returns their redirect location and status code.
  • The check_redirects function takes base_url and paths as arguments.
  • The script combines the base URL with each relative path using urljoin.
  • The script sends a GET request to each combined URL and prints the HTTP status code and final URL after any redirects, or indicates if there were no redirects.
  • The main block checks for enough command-line arguments and calls check_redirects with the base URL and relative paths.

Requirements

  • Python 3 minimum
  • requests library - this script will detact if this isn't installed and prompt the user to install it.

Usage

python <path to file>/check_redirects.py <base_url> <path1> <path2> ...

For a base URL of 'https://www.example.com' and the paths '/women/shoes' and '/men/shirts':

Output Examples

For a base URL of 'https://www.example.com' and the paths '/women/shoes' and '/men/shirts':

python Ashley_Code/URL_Redirect_Checker/check_redirects.py https://www.example.com /women/shoes /men/shirts

Redirects

-------------------------------------------------------------------------------------

♡ Redirect Applied ♡

    Full redirect chain
        Original URL : https://www.example.com/dogs
        -> Final URL : https://www.example.com/cute-dogs

    Status code chain:  301 -> 200

-------------------------------------------------------------------------------------
Final status & URL: (200) https://www.example.com/cute-dogs
-------------------------------------------------------------------------------------

No Redirect

-------------------------------------------------------------------------------------

♡ No redirect applied ♡
    Complete URL: https://www.example.com/cute-dogs
    Status code : 200

-------------------------------------------------------------------------------------

Output with more than one in the chain

-------------------------------------------------------------------------------------

♡ Redirect Applied ♡
    Full redirect chain
        Original URL : https://www.example.com/dogs
        -> Final URL : https://www.example.com/cute-dogs
    Status code chain:  301 -> 200

-------------------------------------------------------------------------------------
Final status & URL: (200) https://www.example.com/cute-dogs
-------------------------------------------------------------------------------------

Requests isn't installed

-------------------------------------------------------------------------------------

* Error * 'requests' is not installed. Please install it using 'pip install requests'

-------------------------------------------------------------------------------------

Error While Processing

-------------------------------------------------------------------------------------

* Error While Processing https://www.example.com/cute-dogs *
        404 Client Error: XYZ

-------------------------------------------------------------------------------------

Timed out

-------------------------------------------------------------------------------------

* This request has timed out *
        https://www.example.com/cute-dogs

-------------------------------------------------------------------------------------

Updates

  1. Monday 8th of July 2024 ~ edit_outputs Tidying up the output and adding in a timeout after 10 seconds with an error message.
  2. Monday 8th of July 2024 ~ Headers Adding common browser User-Agents, this acts more like curl (used my script IRL and the output compared to curl differed)
  3. Wednesday 7th of August 2024 ~ Made the outputs pretty.
  4. Thursday 8th of August 2024 ~ Added more Headers, switched from GET to HEADto mimic curl -IL closer. Added a requests.Session to maintain headers and cookies across requests
  5. Wednesday 14th of August 2024 ~ Added check_dependencies for the requests library, it will prompt the user to install requirements.txt if it is not installed.
  6. Thursday 22nd of August 2024 ~ created a dynamic line separator function that bases the number of - on the width of the terminal.

About

Script to find out redirect history and error codes - useful tool to test redirects after applying them

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages