Introduction
cURL can be used to diagnose website issues when DNS records are not pointed at the server you'd like to test.
cURL has two methods for defining a different host than the request: the --resolve flag and the -H header modification flag.
Procedure
The first example uses the '-H' flag to modify the 'Host' header:
curl -IL -H"Host: domain.tld" http://IP.ADDRESS.OF.SERVER/path-to-file.php
This command uses the following options:
- '-I': Print header information instead of rendered content
- '-L': Follow redirects
- '-H': Specify custom header; in this case, the Host header.
- Apache uses this header when determining which VirtualHost to serve.
- 'http://': Specify the protocol
- As this is before you have configured DNS, you will not have an SSL certificate installed
- 'IP.ADDRESS.OF.SERVER': Replace with the desired host IP for testing
- '/path-to-file.php': Optionally, a path can be specified
Alternatively, you can use the '--resolve' flag. This can be desirable if your application redirects to other subdomains, such as 'www,' or forces HTTPS redirection within the application. As this command is more visually complex, it has been split between multiple lines for readability:
curl -IL --insecure \
--resolve domain.tld:80:SERVER-IP \
--resolve domain.tld:443:SERVER-IP \
--resolve www.domain.tld:80:SERVER-IP \
--resolve www.domain.tld:443:SERVER-IP \
http://domain.tld/path-to-file.php
This command uses the following options:
- '-I': Print header information instead of rendered content
- '-L': Follow redirects
- '--insecure': Ignore SSL warnings
- '--resolve': Override DNS resolution using the format "domain.tld:port:IP"
- For each http:80 and https:443
- For each the domain and the www subdomain
- 'SERVER-IP': Replace with the desired host IP for testing
- 'http://domain.tld': Replace with the testing domain
- '/path-to-file.php': Optionally, a path can be specified
Comments
0 comments
Article is closed for comments.