I have a subdomain for example XYZ.com I want XYZ.com to redirect to XYZ.com/index.html
I want XYZ.com/(anystring) to be a dynamicLink.
My firebase.json
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssocition" : "AUTO",
"rewrites":[
{
"source":"/**",
"dynamicLinks": true
}
]
}
}
Short dynamiclink works but the long dynamic link : XYZ.com/?link=abc redirects to index.html for some reasons. What am I doing wrong?
Related
I tried to rewrite the destination from index.html to app.html like in this anwser but somehow it's not working. In the picture below is my directory structure. Maybe I am using a wrong path and cant see it.
The contents of my firebase.json
{
"hosting": {
"public": "src",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
},
"emulators": {
"hosting": {
"port": 8080
},
"ui": {
"enabled": true
}
},
"rewrites": [
{
"source": "**",
"destination": "/app.html"
}
]
}
I'd like any traffic that comes to:
mysite.com/suppliers/add-supplier
To be directed to add-supplier.html when the path is identified in my firebase.json config file. I've tried this:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"redirects": [
{
"source": "/suppliers/add-supplier",
"destination": "/add-supplier.html"
}
],
"cleanUrls": true
},
"storage": {
"rules": "storage.rules"
}
}
Even though this identifies and redirects correctly, it gets rid of the suppliers/add-supplier path and makes it mysite.com/add-supplier
Is there a way to retain the original URL while also redirecting to the correct HTML page?
You have two options:
Use a rewrite instead of a redirect:
"rewrites": [
{
"source": "/suppliers/add-supplier",
"destination": "/add-supplier.html"
},
{
"source": "**",
"destination": "/index.html"
}
]
Remove the redirect entirely, and place your file at suppliers/add-supplier.html instead of in the root
I combined #samthecodingman's answer with some changes and got it working:
Moved page to new directory
I moved the add-supplier.html file to a new folder called suppliers inside the public directory so that it's suppliers/add-supplier.html
firebase.json:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/suppliers/add-supplier",
"destination": "suppliers/add-supplier.html"
}
],
"cleanUrls": true
},
"storage": {
"rules": "storage.rules"
}
}
This will correctly load the page but the CSS, media and JS files will not be identified. To fix this, change all your resource files to have ../ in the front:
before changing: <link href="dist/css/style.css" rel="stylesheet" type="text/css">
after changing: <link href="../dist/css/style.css" rel="stylesheet" type="text/css">
I'm using firebase hosting. I have index.html file.
It's opening via Both Firebase URL and Custom Domain.
If anyone tries open example.com it should open index.html
But if anyone try to open example.com/?link=https://google.com it should dynamically open the URL in link parameter.
I don't know what I'm doing wrong. Even if the link parameter is present. It still opens the index.html file.
Here is my firebase.json
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [
{
"source": "/?link**",
"dynamicLinks": true
},
{
"source": "!/?link**",
"destination": "/index.html"
}
]
}
}
You should remove the rewrite rule for index.html
{
"source": "!/?link**",
"destination": "/index.html"
}
and remove ? on the dynamicLinks rewrite rule source. It should look like this.
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [{
"source": "/link**",
"dynamicLinks": true
}]
}
}
Deploy the changes again and this should set https://example.com/link as your Dynamic Link domain. You can test if the FDL domain functional by manually adding FDL parameters on the domain.
i.e. https://example.com/link?link=https://google.com
My intention is to redirect https://example.com/admin to my firebase function named admin. So I have the following code in the firebase.json:
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/admin{,/**}",
"function": "admin"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
I've followed the instructions from this website: https://firebase.google.com/docs/hosting/functions
Using my browser, if I go to https://my-server-my-project.cloudfunctions.net/admin everything works an looks fine. But if I go to https://example.com/admin, this is what I get instead:
firebase.json:
{
"hosting": {
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"headers": [ {
"source" : "**/*.#(otf|woff|woff2|eot)",
"headers" : [ {
"key" : "Access-Control-Allow-Origin",
"value" : "*"
} ]
}, {
"source" : "**/*.#(css|js|png)",
"headers" : [ {
"key" : "Cache-Control",
"value" : "max-age=14400"
} ]
} ]
}
}
I am unable to deploy static website in Firebase hosting with firebase deploy command. Error I am getting is:
Error: There was an error loading firebase.json:
Unexpected token ' ' at 3:1
"rewrites": [
^
What exactly is the error?
I tried removing all the whitespaces, tabs & then tried firebase deploy, this time it was successfully deployed.
Still don't know what caused this error. Anyways, thanks SO community.