Godwin Alex Ogbonda
Godwin Alex Ogbonda

Reputation: 97

Replacing - sign with + Query string in htaccess

I have tried my best but ony little of it works, I want to replace - to + sing withing a specific query string in a category.

i want to replace

https://www.example.com/stack/?s=over-flow

to

https://www.example.com/stack/?s=over+flow

I have tried my best with the below code

RewriteCond %{QUERY_STRING} ^(.+)-(.+)$
RewriteRule ^(.*)$ /$1?%1+%2 [L,R=301,NE]

It works but it breaks other part of my site containing - sign in the url

I want it specifically on /stack/?s= only

Please help me out, thanks in advance

Upvotes: 1

Views: 17

Answers (1)

anubhava
anubhava

Reputation: 785156

You may use this rule to target a specific query string with only single parameter:

RewriteCond %{QUERY_STRING} ^(s=[^&-]+)-([^&]+)$ [NC]
RewriteRule ^(stack/?)$ /$1?%1+%2 [L,R=301,NE]

Upvotes: 1

Related Questions