When setting up Google Search Console for a Next.js project, you might need to verify your site ownership by uploading a verification file. However, Next.js's file system routing can make it tricky to place this file in the correct location. Does it go in the public
directory or app
or pages
directory?
When google is suggesting path for the verification file, it might look like this:
https://yoursite.com/google1234567890.html
And you might think sure I can go and place it in the root of the project, but that won't work because Next.js doesn't serve files from the root directory directly. I know, the perils of working with vscode day to day, you might think that the root of the project is the same as the root of the site, but it's not(well you know but it just becomes a habit where root is root, right?).
So you place the file and press on that verify button, and you get an error like this:
Error: The verification file could not be found at the specified URL.
Please ensure that the file is accessible at https://yoursite.com/google1234567890.html
To resolve this, you need to place the verification file in the public
directory of your Next.js project. The public
directory is where Next.js serves static files from, and anything placed there will be accessible at the root of your site.
For example, if you have a file named google1234567890.html
, you should place it in the public
directory like this:
your-nextjs-project/
├── public/
│ ├── google1234567890.html
├── pages/
│ ├── index.js
├── app/
│ ├── page.js
├── package.json
└── ...
And then you can access it at:
https://yoursite.com/google1234567890.html
Now the verification should work without any issues. Made the same mistake, although I was able to figure it out quickly, but thought it might help someone else who is facing the same issue.
Back To All Blogs