Karl Johan Vallner
Karl Johan Vallner

Reputation: 4310

replace all instances of string in htaccess

Simple question here.

I need to replace all instances of a string in the URL with another string.

IE. I need to replace every instance of "test" in the URL, with .htaccess code.

For example "www.example.com/test/A/test/B/test" will become "www.example.com/REP/A/REP/B/REP".

I can produce a script that replaces "test" with "REP", when "test" is not at the end or the beginning of the script. But I cannot come up with a final script to replace "test" everywhere.

My code:

RewriteRule ^test\/(.*) REP/$1 [L,R=301]

Thanks!

Upvotes: 1

Views: 409

Answers (1)

Karl Johan Vallner
Karl Johan Vallner

Reputation: 4310

I found an answer, that is all knowing and beatiful.

RewriteRule ^(.*)test(.*)$ $1FIN$2 [R=301,L]

Upvotes: 1

Related Questions