I need to change one word which is there in all URLs linking to my site.
I tried with the following rule but it works fine only when the word is the first one in URL
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} ^/foo(?:/)?(.*)$
RewriteRule ^[/]?foo[/]?(.*) /bar/$1 [R=permanent,L,NE]
When I add wildcard entries to REQ_URI, output is not proper, I am not sure how to handle replacements. http://www.example.com/abc/def/foo/ghi is rewirtten as http://www.example.com/bar/abc/def
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} ^(.*)/foo(?:/)?(.*)$
RewriteRule ^(.*)[/]?foo[/]?(.*) /bar/$1 [R=permanent,L,NE]
How do I correct the rewrite rule ?
This assumes foo is a folder name. Generally when setting something like this up you want to have some sort of delimiter (in this case the slashes) so that, for example, “food” doesn’t become “bard”.