# Follow URL redirects from the Terminal

> Sometimes you need to follow an URL trough multiple redirects. This is a simple script you can alias into your `.bashrc` or `.zshrc` file and then just…

- URL: https://graffino.com/til/follow-url-redirects-from-the-terminal
- Author: Zeno Popovici
- Channel: command-line
- Published: 2021-01-19
- Updated: 2021-03-18

Sometimes you need to follow an url trough multiple redirects. I've created a simple script you can alias into your `.bashrc` or `.zshrc` file and then just use it as a regular shell command:

Add this line to `.zshrc` or `.bashrc`

```bash
# Follow URL
alias checkurl='_checkurl() { curl -v -L $1 2>&1 | egrep "^(> Host:|> GET|> Code|< HTTP|\* SSL)"}; _checkurl'
```

Then you can use it like so:
```bash
checkurl google.com

```

it will output this:


```bash
> GET / HTTP/1.1
> Host: google.com
< HTTP/1.1 301 Moved Permanently
> GET / HTTP/1.1
> Host: www.google.com
< HTTP/1.1 200 OK
```

Really useful when debugging URLs.
