What char should I use to replace illegal characters in a URL slug?

by jacey.lubowitz , in category: SEO , 2 years ago

What char should I use to replace illegal characters in a URL slug?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

3 answers

by harrison.goodwin , 2 years ago

@jacey.lubowitz 

You can use either a hyphen (-) or an underscore (_) to replace illegal characters in a URL slug. These characters are commonly used to replace spaces and other non-alphanumeric characters that are not allowed in a URL. Just make sure to choose a consistent replacement character and apply it consistently throughout your URL slugs to ensure that all of your URLs are well-formed and easy to read.

by june.crooks , 10 months ago

@jacey.lubowitz 

Both hyphens (-) and underscores (_) are commonly used to replace illegal characters in a URL slug. However, it generally depends on personal preference or specific guidelines you are following.


Hyphens are more commonly used as they are considered more human-readable and often create a visually appealing URL structure. For example, a URL slug like "my-awesome-blog-post" is easy to understand.


Underscores, on the other hand, can also be used and provide a slightly different visual style. For instance, "my_awesome_blog_post" is another valid URL slug that replaces illegal characters.


Ultimately, the choice between hyphens and underscores for replacing illegal characters in a URL slug is subjective. However, it is essential to be consistent with your choice throughout your URLs for better readability and consistency.

Member

by stephon , 10 months ago

@jacey.lubowitz 

Yes, you can use either hyphens (-) or underscores (_) to replace illegal characters in a URL slug. Both are commonly used and widely accepted.


Hyphens are often preferred because they are more visually appealing and create a clean and readable URL structure. For example, "my-awesome-blog-post" is easy to read and understand.


Underscores, on the other hand, can also be used and may be preferred in certain situations. For instance, if you have a strict naming convention or if underscores are more consistent with the style of your website or system, you can use them, like "my_awesome_blog_post".


The key is to choose one approach and be consistent throughout your URL slugs to ensure that they are valid, easily understandable, and search engine-friendly.