Skip to content
Advertisement

Building a custom canonical url in python

I want to build a canonical url for my website: my.com

here are the requirements:

  1. always include www subdomain
  2. always use https protocol
  3. remove default 80 and 443 ports
  4. remove trailing slash

Example:

JavaScript

This is what I have tried:

JavaScript

But I don’t know how to join these url components?

Advertisement

Answer

You just need to write a simple function,

JavaScript

Execution,

JavaScript

Few issues of your code, parsed.scheme == ‘https’ -> It’s not the right way to assign a value, It’s a statement gives True or False And parsed.scheme doesn’t allow to setttr.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement