richard grantham
richard grantham

Reputation: 23

htaccess rewrite replace space with -

I am really stuck on a rewrite rule and wonder if anyone can help.

I am pulling data from a database, and as an example the field "name" i use sometimes has 2 words in with a space between. I use this alot on the site but in the url i want to replace the space with a - as i use this field as a variable to determine the record i want to pull.

so i need to turn clubs/premier league/manchester city/

into

clubs/premier-league/manchester-city/

thanks in advance

richard

Upvotes: 2

Views: 3935

Answers (1)

anubhava
anubhava

Reputation: 784868

Can you try this rule in your .htaccess:

RewriteEngine on
RewriteRule ^clubs/([^\s]+)\s([^\s]+)/([^\s]+)\s([^\s]+)/$ /clubs/$1-$2/$3-$4/ [R=302,NC,L]

Upvotes: 2

Related Questions