Results 1 to 3 of 3

Thread: [RESOLVED] Rewriting content on the fly

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Resolved [RESOLVED] Rewriting content on the fly

    Hello there,
    I have what may look as a strange request.

    I have to change the content of a webpage hosted on Apache, without actually changing the file. The webpage can be a .php, .html or .htm.
    What I want to do is to rewrite the url of the images it contains, so they point to another location. For instance, imagine this is part of the original content:

    <img src="images/logo.jpg" alt="Company logo" />

    I have to rewrite the src value, and make it look like this:

    <img src="http://whatever.anotherdomain.com/images/logo.jpg" alt="Company logo" />

    For a reason I won't explain (long story), I can't just open the page and modify the src attribute manually. It has to be done by a script, either a Javascript or other method.

    Even if I'm able to accomplish this via Javascript, I'm looking for another solution because if the user disables javascript, the src value is not rewritten.

    My question:
    Can I do this with an .htaccess rule? How?
    If not, are there other options?

    Many Thanks in advance.


    edit: I suddenly remembered that I can add the <base> tag to the page instead of rewriting all the SRCs, and get the same result. The question is still there: how do I add that tag on the fly?
    Last edited by BrightSoul; Oct 15th, 2007 at 03:43 AM.
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Rewriting content on the fly

    Check out the file functions. You can make a script that can go through your pages and add that, but it might be difficult.
    My usual boring signature: Something

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Resolved Re: Rewriting content on the fly

    Thanks for your reply.
    In the meantime I realized the proper use for the .htaccess file. I didn't have to necessarly rewrite the contents of my pages, but just redirecting the requests was enough.

    I solved my problem by putting the following inside the .htaccessfile

    Code:
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !^www.myotherdomain.com$ [NC]
    RewriteRule ^(.*)\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ http://www.myotherdomain.com/$1\.$2 [L,R=301]
    ie. Apache redirects all the incoming requests to image files to the other domain.
    Thanks for helping anyways.
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width