Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase: Redirect to page when a URL path pattern is identified

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to retain the original URL while also redirecting to the correct HTML page?

>Solution :

You have two options:

  1. Use a rewrite instead of a redirect:
"rewrites": [
  {
    "source": "/suppliers/add-supplier",
    "destination": "/add-supplier.html"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]
  1. Remove the redirect entirely, and place your file at suppliers/add-supplier.html instead of in the root
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading