InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Networking tutorials

  • DIG quick start tutorial
  • Dig - list all dns records
  • How to view wifi connection speed on Mac
  • Linux iptables - Nat port forwarding using PREROUTING
  • Linux iptables and ip6tables examples
  • Ngrep - quick start guide
  • Use nc to check if a remote port is reachable
  • Use nc to listen to tcp or udp port
  • Use nc to test HTTP url redirection
  • add more DNS servers to Wi-Fi interface on Mac
  • locally override website host to IP mapping
  • use nc to print headers from browser
 
  • Home
  • > Tutorials
  • > Networking

how to use netcat (nc) to test HTTP url redirection

By admin | Last updated on Mar 18, 2016

Netcat (nc) is pretty powerful command line tool on Linux & Mac and can be used to send data on network. It can be quickly used to communicate with any webserver with custom headers. These headers can have custom url, Host, User-agent, etc. Here are some HTTP url redirection scenarios which can be tested with netcat.

Test basic redirection

To test if /feed/ redirects to feedburner url run this on command line (Mac or Linux):

printf "GET /feed/ HTTP/1.1\nHost:infoheap.com\nUser-Agent:Firefox\n\n" | nc infoheap.com 80

Here expected outcome is a HTTP 302 redirect to http://feeds.infoheap.com/infoheap. Here is the initial part of the outcome on Mac:

HTTP/1.1 302 Found
Date: Wed, 01 May 2013 15:36:38 GMT
Server: Apache/2.2.22 (Ubuntu)
Location: http://feeds.infoheap.com/infoheap
Vary: Accept-Encoding
Content-Length: 296
Content-Type: text/html; charset=iso-8859-1

Test Host based redirection

To test if https://www.infoheap.com/ redirects to https://infoheap.com/, run this on command line:

printf "GET / HTTP/1.1\nHost:www.infoheap.com\nUser-Agent:Firefox\n\n" | nc infoheap.com 80

Here expected outcome is a HTTP 301 redirect to https://infoheap.com/. Here is initial part of the real outcome on Mac:

HTTP/1.1 301 Moved Permanently
Date: Wed, 01 May 2013 15:43:02 GMT
Server: Apache/2.2.22 (Ubuntu)
Location: https://infoheap.com/
Vary: Accept-Encoding
Content-Length: 310
Content-Type: text/html; charset=iso-8859-1

Test user-agent based redirection

To test if /feed/ url is not redirected for User-Agent=Feedburner, run this on command line:

printf "GET /feed/ HTTP/1.1\nHost:infoheap.com\nUser-Agent:Feedburner\n\n" | nc infoheap.com 80

Here expected outcome is no redirect and xml content should be served. Here is initial part of the real outcome on Mac:

HTTP/1.1 200 OK
Date: Wed, 01 May 2013 15:46:04 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Vary: Accept-Encoding
X-Pingback: https://infoheap.com/xmlrpc.php
Last-Modified: Wed, 01 May 2013 12:52:39 GMT
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

 

Netcat can be used in many such scenarios to test if redirection, etc. is working fine. It can be pretty useful and time saver tool once we get comfortable with it.

Suggested posts:

  1. How to create and use color palettes in Inkscape
  2. Find image unique colors and bit depth using imagemagick identify
  3. How to use your own domain name for feedburner feed urls
  4. Alexa rank – how reliable is it?
  5. Github tutorial for beginners
  6. How to remove password from pdf using Chrome
  7. How to connect to mysql server using ssh port forwarding
  8. How to display wordpress page list with specific custom field value
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Networking, Tutorials, Webmaster
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress