RT: some website servers are configured with the 404 rule: redirect to the relative URL of the current website. In this case, infinite redirection may occur. When you use CURL to obtain data, how should we solve this problem? RT, some website servers are configured
404Rule: redirect to the current website
Relative URLIn this case
Unlimited redirectionIn use
CURLHow can I solve this problem when obtaining data?
Reply content:
RT, some website servers are configured404Rule: redirect to the current websiteRelative URLIn this caseUnlimited redirectionIn useCURLHow can I solve this problem when obtaining data?
1 If multiple redirection is required, set the curl to follow (CURLOPT_FOLLOWLOCATION)
2. If multiple redirection attempts are unacceptable, set the maximum number of redirect requests.
3. If you need to analyze the http response by yourself, make a decision.
Do you want to limit the number of redirection times?
CURLOPT_MAXREDIRSThe parameter can limit the maximum number of HTTP redirects. This option is used with CURLOPT_FOLLOWLOCATION ..
Document address: http://php.net/manual/zh/function.curl-setopt.php
Curl_setopt ($ ch, CURLOPT_MAXREDIRS, 5); // redirect up to 5 times
CURL can automatically follow 301, see https://github.com/leaps/httpclient/blob/master/src/Leaps/HttpClient/Adapter/Curl.php
The first line contains related code.