Software >> OS >> Unix >> curl >> How to force curl to follow the http 301 redirect response

Example we have a URL http://localhost/owndir which is a directory containing and index document


## When running curl without any option, It will just display the HTTP 301 redirect instruction from the webserver to reload http://localhost/owndir/

root@system1 html]# curl http://localhost/owndir
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://localhost/owndir/">here</a>.</p>
</body></html>


## To automatically follow the redirect instruction do the following

root@system1 html]# curl -L http://localhost/owndir
<html><body>local access only</body></html>