W
Wasp6d ago
Sven

How to not show fly.io domain on google search

Is there anyone that knows a way such that the fly.io domain is not shown in a google search? i have setup my custom domain..
4 Replies
kapa.ai
kapa.ai6d ago
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To prevent your fly.io domain from showing up in Google search results while using your custom domain with a Wasp app, you need to take a few specific steps: 1. Make sure your custom domain is properly set up with Fly.io. Based on the knowledge sources, you should have already: - Added your domain to your Fly client app - Added the proper DNS records (A and AAAA) - Set your custom domain as the WASP_WEB_CLIENT_URL environment variable for your server app Deploying with the Wasp CLI 2. To prevent the fly.io domain from appearing in search results, you should: - Make sure all your internal links use your custom domain, not the fly.io domain - Set up proper redirects from the fly.io domain to your custom domain - Consider adding canonical URL tags in your HTML head to indicate your custom domain is the preferred URL While the knowledge sources don't specifically address hiding the fly.io domain from Google search results, these are standard SEO practices that should help. You might also want to consider: - Using Google Search Console to request removal of the fly.io URLs - Setting up robots.txt on the fly.io domain to discourage crawling If you're using the OpenSaaS template, you might find additional SEO capabilities there, as mentioned by a community member who had success with Google search rankings even without a dedicated landing page: "A lot of hype around needing SSR for good SEO is exaggerated" and Wasp allows you to add OG tags in the head property of the main.wasp file. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
toticozeni
toticozeni6d ago
@Sven hello, the bot is right, setting up DNS and Canonical URL right should solve the problem for you. Let us know if you have any questions.
NEROX
NEROX6d ago
To directly eliminate the root of the problem you can create a small redirection middleware:
import { type MiddlewareConfigFn } from 'wasp/server'
import { type RequestHandler } from 'express'
import { URL } from 'url'

const redirectToPrimaryDomain: RequestHandler = (req, res, next) => {
// Use WASP_WEB_CLIENT_URL for the canonical domain.
const primaryDomainUrl = process.env.WASP_WEB_CLIENT_URL
if (!primaryDomainUrl) {
// Allow requests if primary domain is not set (e.g., local dev).
return next()
}

try {
const expectedHost = new URL(primaryDomainUrl).host
const currentHost = req.headers.host

// If the request host doesn't match the primary domain, redirect.
if (currentHost && currentHost !== expectedHost) {
const redirectUrl = `${primaryDomainUrl}${req.originalUrl}`
// 301 Permanent Redirect for SEO.
return res.redirect(301, redirectUrl)
}
} catch (error) {
console.error('Error processing redirect middleware:', error)
// Continue without redirecting in case of error (e.g., invalid URL in env var).
}

// Proceed if hosts match or an error occurred.
return next()
}

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Prepend the domain redirection middleware to the existing middleware chain.
const newMiddlewareConfig = new Map()
newMiddlewareConfig.set('redirectToPrimaryDomain', redirectToPrimaryDomain)
middlewareConfig.forEach((value, key) => {
newMiddlewareConfig.set(key, value)
})

return newMiddlewareConfig
}
import { type MiddlewareConfigFn } from 'wasp/server'
import { type RequestHandler } from 'express'
import { URL } from 'url'

const redirectToPrimaryDomain: RequestHandler = (req, res, next) => {
// Use WASP_WEB_CLIENT_URL for the canonical domain.
const primaryDomainUrl = process.env.WASP_WEB_CLIENT_URL
if (!primaryDomainUrl) {
// Allow requests if primary domain is not set (e.g., local dev).
return next()
}

try {
const expectedHost = new URL(primaryDomainUrl).host
const currentHost = req.headers.host

// If the request host doesn't match the primary domain, redirect.
if (currentHost && currentHost !== expectedHost) {
const redirectUrl = `${primaryDomainUrl}${req.originalUrl}`
// 301 Permanent Redirect for SEO.
return res.redirect(301, redirectUrl)
}
} catch (error) {
console.error('Error processing redirect middleware:', error)
// Continue without redirecting in case of error (e.g., invalid URL in env var).
}

// Proceed if hosts match or an error occurred.
return next()
}

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Prepend the domain redirection middleware to the existing middleware chain.
const newMiddlewareConfig = new Map()
newMiddlewareConfig.set('redirectToPrimaryDomain', redirectToPrimaryDomain)
middlewareConfig.forEach((value, key) => {
newMiddlewareConfig.set(key, value)
})

return newMiddlewareConfig
}
And as Franjo has said, add Canonical as well.
Sven
SvenOP6d ago
what does this do? i already have some redirect when people come on my fly.io domain or is this somethig different? how do i properly implement this in my code? also i do not understand how i do that Canonical part.... could you dm me @NEROX

Did you find this page helpful?