logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_sed
Author
DaveA66



Joined: 13 Mar 2015
Posts: 4

PostPosted: Fri 13 Mar '15 17:18    Post subject: mod_sed Reply with quote

Hi

I am using (or trying to) mod_sed - I want to add an advertising banner to every web page served.

the problem is I cannot seem to make the OutputSed command recognise absolute paths. I can make it work with a relative path for both the image and the <a> href, but not absolute, which is awkward as the webite wiill have different directories for content created by FTP for hosting results of different tournaments.

This is what I have in my vhost.conf file for the banner image:
Code:

 <Directory "/var/www/fencing-results.co.uk">
                Options Indexes FollowSymLinks
                AllowOverride all
                Order allow,deny
                Allow from all
                AddOutputFilter Sed htm
                OutputSed "s/<body>/<body><img src=\"\/var\/www\/fencing-results.co.uk\/banner.jpg\">/g"
        </Directory>



Any help and advice appreciated, I am rather new to Apache/Linux Smile
Back to top
DaveA66



Joined: 13 Mar 2015
Posts: 4

PostPosted: Fri 13 Mar '15 17:19    Post subject: Reply with quote

I should add that the above just leaves a placeholder for the image when the pages are rendered, so I know the sed bit is working it just will not locate the file!

Thanks
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 13 Mar '15 19:16    Post subject: Reply with quote

On any other day would this work directly in your html page?

<img src="/var/www/fencing-results.co.uk/banner.jpg">

I doubt it. You cannot call anything like that in the html page because everything is relative to the DocumentRoot. What Apache would try to serve because your browser would request it would be;
/var/www/fencing-results.co.uk/var/www/fencing-results.co.uk/banner.jpg

No, instead you would just have this in your image tag;
<img src="/banner.jpg">

Just because you're doing this in the config, what mod_sed is going to do is change the text/html of the output. The browser is still responsible for actually requesting the image.

So this should work for you better I'd imagine;
OutputSed "s/<body>/<body><img src=\"\/banner.jpg\">/g"

You can also use | in sed for the separator and not have to escape paths;
OutputSed "s|<body>|<body><img src=\"/banner.jpg\">|g"
Back to top
DaveA66



Joined: 13 Mar 2015
Posts: 4

PostPosted: Fri 13 Mar '15 19:59    Post subject: Reply with quote

Hi

thanks for the reply!

Yes, that was it, what I had not realised was that everything would be relative to the root.
My background is more IIS

I had exactly the same problem of I tried to put the image inside an <a></a> as well, I could not use an absolute URL. (or get any valid URL to work). Thsi was trying to link to another site completely.

If I tried to link the image to, say http://domain.com
The actual URL requested by the browser would be

http://fencing-results.co.uk/nafc/spring15/domain.com
Or something similar.
Back to top
DaveA66



Joined: 13 Mar 2015
Posts: 4

PostPosted: Tue 17 Mar '15 19:03    Post subject: Reply with quote

Is it possible to use mod_sed (Or OutputSed more correctly) to execute some PHP to provide the changed content.
So, roughly, OutputSed "s/Text to search For/Text returned by some code/g"

Sorry if that sound a bit clueless Smile

Thanks!
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 17 Mar '15 23:46    Post subject: Reply with quote

Not sure, it would depend on where in the chain mod_sed sits, is it before the output is sent to PHP or after? I suppose there's no better way to know for sure than to try. What is the worst that can happen? It doesn't work!
Back to top


Reply to topic   Topic: mod_sed View previous topic :: View next topic
Post new topic   Forum Index -> Apache