Check if apache URL redirects work with curl

apache URL redirects work with curl

With curl you can check if redirects in your apache or .htaccess configuration works. You can add the options -I and -L for a better result, if there are multiple redirects. The option -I will get only the header of the page and option -L allows multiple redirects. In this example, the page http://www.example.com/ gets redirected to https://example.com/, with SSL and no www:

$ curl -IL http://www.example.com/
HTTP/1.1 301 Moved Permanently
Date: Sat, 08 Sep 2018 20:08:07 GMT
Server: Apache/2.4.25 (Debian)
Location: https://www.example.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 301 Moved Permanently
Date: Sat, 08 Sep 2018 20:08:07 GMT
Server: Apache/2.4.25 (Debian)
Location: https://example.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Sat, 08 Sep 2018 20:08:07 GMT
...

from $ man curl:

-I, --head
(HTTP/FTP/FILE)  Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file size and last modification time only.

-L, --location
(HTTP/HTTPS)  If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. If used together with -i,  --include  or -I,  --head, headers from all requested pages will be shown.