Jason Stanley
Jason Stanley

Reputation: 179

mod_rewrite Replace string in URL

I am trying to achievement replacement of a string in a URL on the Apache level.

So I have a URL like :

https://barred.v.com/sorter.do?clientId=testvalue1

I want this to be redirected to

https://barred.v.com/sorter.do?nai=testvalue1

So look for clientId and replace by nai .

Is this even possible at the Apache layer ? with mod_rewrite ?

Upvotes: 0

Views: 1304

Answers (2)

Rounin
Rounin

Reputation: 29511

In the root folder of

http://example.com/

upload an .htaccess file, containing the following:

RewriteEngine On

RewriteCond %{QUERY_STRING} clientId=(.+)
RewriteRule ^sorter\.do http://%{HTTP_HOST}/sorter.do?nai=%1 [NC,L]

Upvotes: 1

Amit Verma
Amit Verma

Reputation: 41249

Try the following :

RewriteEngine on
RewriteCond %{THE_REQUEST} /sorter\.do\?clientId=([^\s]+) [NC] 
RewriteRule ^sorter\.do$ http://%{HTTP_HOST}/?nai=%1 [NC,L]

Upvotes: 0

Related Questions