Replace spaces(%20) for multiple word tags in url

rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Replace spaces(%20) for multiple word tags in url

Post by rax »

By default, multiple word tags look like this /tag/new%20car%20videos/

The url would look better using hyphens /tag/new-car-videos/

Is using mod_rewrite/RewriteRule the only way to accomplish this or is there another option?
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Replace spaces(%20) for multiple word tags in url

Post by admin »

You can replace spaces with dashes in templates
Script will recognize it anyway
Don't forget to run script update
rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Re: Replace spaces(%20) for multiple word tags in url

Post by rax »

How would this be done in templates?
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Replace spaces(%20) for multiple word tags in url

Post by admin »

You can use str_replace() php function
Also don't forget about tag_prefixes
Don't forget to run script update
rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Re: Replace spaces(%20) for multiple word tags in url

Post by rax »

What tag_prefixes should be used?
rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Re: Replace spaces(%20) for multiple word tags in url

Post by rax »

Also, can you show an example here, the space(%20) in tags doesn't exist until the <!--TAG1--> is already processed by the server. So how would we use str_replace() to make this work?
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Replace spaces(%20) for multiple word tags in url

Post by admin »

I mean you can use it right in templates
Don't forget to run script update
rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Re: Replace spaces(%20) for multiple word tags in url

Post by rax »

Can you please show me an example of how this would work using str_replace() php function and tag prefixes? I don't see how this could work as the <!--TAG1--> variable hasn't been processed yet by the server to show the actual tag, again the url example I'm using is domain.com/tag/new%20car%videos/
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Replace spaces(%20) for multiple word tags in url

Post by admin »

<!--TAG1--> becomes <? echo str_replace(' ', '-', '<!--ESCAPED_TAG1-->') ?>
Don't forget to run script update
rax
Posts: 172
Joined: Sat Oct 05, 2013 9:28 pm

Re: Replace spaces(%20) for multiple word tags in url

Post by rax »

Thank you.

I had tried using that code with '%20' in the single quotes, didn't think to try the ' ' blank space...
Post Reply