0

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 ?

2 Answers 2

1

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]
Sign up to request clarification or add additional context in comments.

2 Comments

It seems to work only when I do Rewrite Rule ^\/sorter.do http://%{HTTP_HOST}/sorter.do?nai=%1 [NC,L] But I am also trying to do : RewriteRule ^\/sorter.do\?clientId(.*)$ /sorter.do?$nai$1 [R=301,L,NE] but it doesnt work. Any idea whats wrong with it ?
In your second example above, it looks like you're trying to rewrite the query string using the RewriteRule. But you can't do that. You need to capture a variable from the RewriteCond as in the example in the post above. Can you give a concrete example of where the lines in the post above don't work? Thanks.
0

Try the following :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.