Can mod-Rewrite append a string in front of a URL and encode the entire thing?

LightHouse

Junior Member
Joined
Apr 9, 2009
Messages
100
Reaction score
50
Trying to get outbound links to all be appended with a jumper script, the URLs have to be encoded before they go through the jumper though. I was hoping to do with with mod_rewrite since i cant change every link on the sites manually.

anyone have any idea, maybe someone has done this already?

if not can someone point me in the right direction to a solution?
 
I don't believe mod_rewrite can do this.
However you could add some javascript to the footer of your page.

Something like this:
Code:
<script type="text/javascript">
  for (var i = 0; i<document.links.length; i++) {
    if(document.links[i].href.match(/http:\/\/mydomain.com\/(.+)/i))
    {
      document.links[i].href = "http://mydomain.com/" + encodeURIComponent($1);
    }
  }
</script>

I haven't tested it but that's a basic example of what you could do to make it work.
 
I don't believe mod_rewrite can do this.
However you could add some javascript to the footer of your page.

Something like this:
Code:
<script type="text/javascript">
  for (var i = 0; i<document.links.length; i++) {
    if(document.links[i].href.match(/http:\/\/mydomain.com\/(.+)/i))
    {
      document.links[i].href = "http://mydomain.com/" + encodeURIComponent($1);
    }
  }
</script>
I haven't tested it but that's a basic example of what you could do to make it work.


would this re-write them on the page or rewrite them outbound. Also does this JS auto encode it or were you referenceing having an encode component in place?
 
This would rewrite them outbound as your browser needs to parse the javascript.
Also encodeURIComponent() is a built in function.
 
Why don't you pass them through an intermediary php script to do the encoding.
 
Back
Top