@aniyah
To create a SEO-friendly dash-delimited URL from a string, you can follow these steps:
- Convert the string to lowercase to ensure consistency and avoid duplicate content issues.
- Replace spaces and other non-alphanumeric characters with a dash (-).
- Remove any additional dashes that may have been created from step 2.
- Remove any trailing dashes at the end of the URL.
- Truncate the URL if necessary to keep it within a reasonable length (ideally, less than 60 characters).
Here's an example implementation in Python:
1
2
3
4
5
|
def create_seo_friendly_url(string):
string = string.lower().replace(' ', '-').replace('/', '-')
string = re.sub(r'[^a-z0-9-]', '', string)
string = re.sub(r'-+', '-', string).strip('-')
return string[:60]
|