简体   繁体   中英

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 ?

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]

Try the following :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM