How to Check URL Status Code in Google Sheets
A free Google Apps Script to check URL status code in Google Sheets. It tests http/https, www and trailing-slash variations and returns the first non-301.
You have a list of URLs in a spreadsheet and you need their HTTP status codes. Checking them one by one in a browser gets old fast. Here is how to check URL status code in Google Sheets without leaving the sheet.
It is a free Google Apps Script that adds a =getStatusCode() function. Paste a URL, get its code in the next cell. The script tests the common http/https and www variations, with and without a trailing slash, and returns the first non-301 code.
Why check URL status code in Google Sheets
A status code tells you whether a URL works. 200 is fine, 404 is gone, 5xx is broken, 301 means it moved. When you are auditing a site, the URLs are usually sitting in a sheet already: a crawl export, a list of redirects to verify, an XML sitemap, or backlinks you are validating. Checking them in the sheet keeps the data where you will analyse it. I lean on this constantly during migrations, where you are validating thousands of old and new URLs at once.
The script
The function has two parts. getStatusCode normalises the URL and builds the variations to test, and tryUrls fetches each one until it gets a non-301 response.
1function getStatusCode(url) {2 var url_trimmed = url.trim();3 if (url_trimmed === '') return '';4 var cache = CacheService.getScriptCache();5 var cacheKey = 'status-' + url_trimmed;6 var cached = cache.get(cacheKey);7 if (cached) return cached;8 // Normalize input (strip protocol + www)9 var clean = url_trimmed10 .replace(/^https?:\/\//, '')11 .replace(/^www\./, '');12 // Base variations (protocol + www)13 var bases = [14 "https://" + clean,15 "https://www." + clean,16 "http://" + clean,17 "http://www." + clean18 ];19 // Add trailing slash variations20 var variations = [];21 bases.forEach(function (b) {22 variations.push(b);23 if (!b.endsWith('/')) {24 variations.push(b + '/');25 }26 });27 var status = tryUrls(variations);28 cache.put(cacheKey, status, 21600); // 6 hours29 return status;30}3132function tryUrls(urlList) {33 var options = { muteHttpExceptions: true, followRedirects: false };34 for (var i = 0; i < urlList.length; i++) {35 try {36 var response = UrlFetchApp.fetch(urlList[i], options);37 var code = response.getResponseCode();38 // Skip 301 - continue testing next version39 if (code == 301) continue;40 return code.toString();41 } catch (e) {42 // Try next variation43 }44 }45 return "Error";46}
The caching matters. Google Sheets re-runs a custom function every time the sheet recalculates, so without a cache you would spend fetch quota fast. This version stores each result for six hours with CacheService, so repeated recalculations do not re-fetch the same URL.
How to use it
- Open the Google Sheet where you want this.
- Go to Extensions, then Apps Script. A blank editor opens.
- Paste the code above, save it (File, Save), and close the editor.
- Back in the sheet, put a URL in a cell, for example A1.
- In another cell, enter =getStatusCode(A1).
- The cell returns the status code: 200, 404, and so on. If every variation fails, it returns Error.
Bulk-check URL status code in Google Sheets
The function works down a column, so checking a list is the same as checking one URL. Paste your URLs into column A, put =getStatusCode(A1) in B1, then fill the formula down the column.
For a whole site, pull a sitemap straight into the sheet with =IMPORTXML("https://example.com/sitemap.xml","//*[local-name()='loc']"), which returns every URL in column A. Then run =getStatusCode() in the column next to it.
It tries all URL combinations automatically: https, https www, http, http www, each with and without a trailing slash, and returns the first non-301 status code. If everything fails, it returns Error.
Redirects, errors and rate limits
The script skips 301s on purpose. It is testing several URL variations, and a 301 usually just means one variation redirects to another. Skipping it and reporting the first real status gives you the destination code rather than the redirect itself.
The six-hour CacheService stores results so repeated sheet recalculations do not re-fetch the same URLs. This is what keeps quota usage low on larger lists.
UrlFetchApp, the service the script uses, has a daily quota: 20,000 fetch calls per day on consumer accounts (gmail.com) and 100,000 on Google Workspace accounts. The current figures are on Google's Apps Script quotas page. For a few hundred or a few thousand URLs you will not notice the limit. For tens of thousands in one sheet, split the job into batches.
When to use a dedicated tool instead
The script is built for quick checks inside data you already have. It only reports a status code. The things it does not do each have a dedicated tool:
- Redirect chains and response headers: my HTTP status tool shows the full hop sequence and the X-Robots-Tag.
- A list of redirects to confirm in bulk: bulk redirect checker.
- Whether a URL is actually indexed: Google index checker.
Other useful Google Sheets functions for SEO
This is one of several Google Sheets SEO workflows I use regularly. A few others worth keeping:
- =IMPORTXML(A1,"//title") pulls the title tag of the URL in A1, handy for spotting missing or duplicate titles.
- The Search Analytics for Sheets add-on pulls Google Search Console data into a tab, which is how I map keyword cannibalization.
- Conditional formatting on the status column flags anything that is not 200.
Frequently asked questions
How do I check a URL status code in Google Sheets?
Add the getStatusCode Apps Script above to your sheet, then use =getStatusCode(A1) where A1 holds the URL. The cell returns the HTTP status code, like 200 or 404.
Why does the script skip 301 redirects?
It tests several variations of a URL, and a 301 usually just means one variation points to another. The script skips the 301 and reports the first variation that returns a real status, so you get the destination's code rather than the redirect.
Can it check status codes in bulk?
Yes. Put the URLs in a column and fill =getStatusCode() down the next column. The six-hour cache keeps repeated recalculations from re-fetching the same URLs.
Does this use up any API quota?
It uses the Apps Script UrlFetchApp quota: 20,000 calls a day on consumer accounts, 100,000 on Workspace. The script caches each result for six hours to limit repeat calls.
What does it return if a URL is unreachable?
It returns Error after trying every http/https, www and trailing-slash variation without a valid response.
Where to go next
Drop the script into any sheet where you already keep URLs and you have status checks on tap, no add-on, no copy-paste. Next time you run a migration or a content audit, pull the URLs into a column, fill the formula, and sort by anything that is not 200. For the redirect chains and headers the function does not cover, send those URLs to a dedicated checker. The pattern that scales is simple: keep the raw URLs and the checks in the same sheet, cache the calls, and reach for a heavier tool only when the question gets deeper than a status code.
About the author
Oleksii Khoroshun
SEO specialist at SE Ranking with 8+ years of technical and on-page work. Led migrations, built ranking strategies for sites from 10K to 100K+ pages, and shipped Chrome extensions for workflows no existing tool handled well. Top Rated on Upwork (100% Job Success Score).
More from the blog
View allDiscovered currently not indexed: what it means and how to fix it
Discovered currently not indexed means Google found your URL but has not crawled it yet. Here are the real causes and the steps to get pages indexed fast.
AEO vs SEO: What's the Difference and How to Measure Both
AEO and SEO target different surfaces but share the same signals. Here is what separates them, where GEO fits in, and how to measure all three in one stack.
How to track AI chatbot traffic in GA4: 3 methods (2026)
GA4 now has a native AI Assistant channel, but it misses most AI sessions. 3 methods to track AI chatbot traffic from ChatGPT, Perplexity, Gemini and more.

