For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2008 > function call in .htaccess ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author function call in .htaccess ?
Peter

2008-01-30, 7:10 pm

Hi,

I use something like this:

RewriteRule ^(.*).png$ ../../templates/png_help/$1.png

The links to png in my pages exist to this subdir, but in fact the png are
located somewhere else in a templates directory.
Now, I'm shuffeling folder layout, in part to support localisation etc.
therefore the location might differ based on variables.

Can I use external variables somehow in .htaccess ?
E.g. {TARGET_DIRECTORY}/templates/png_help/$1.png

Or call a function that outputs the directory ?
e.g. <?php echo DIR ?>/templates/png_help/$1.png

or .... ???

Your insights appreciated.


Peter

2008-01-30, 7:10 pm

(Apologies if this is sent twice, server issues it seems)

Hi,

I use something like this:

RewriteRule ^(.*).png$ ../../templates/png_help/$1.png

The links to png in my pages exist to this subdir, but in fact the png are
located somewhere else in a templates directory.
Now, I'm shuffeling folder layout, in part to support localisation etc.
therefore the location might differ based on variables.

Can I use external variables somehow in .htaccess ?
E.g. {TARGET_DIRECTORY}/templates/png_help/$1.png

Or call a function that outputs the directory ?
e.g. <?php echo DIR ?>/templates/png_help/$1.png

or .... ???

Your insights appreciated.


Erwin Moller

2008-01-30, 7:10 pm

Peter wrote:
> (Apologies if this is sent twice, server issues it seems)
>
> Hi,
>
> I use something like this:
>
> RewriteRule ^(.*).png$ ../../templates/png_help/$1.png
>
> The links to png in my pages exist to this subdir, but in fact the png are
> located somewhere else in a templates directory.
> Now, I'm shuffeling folder layout, in part to support localisation etc.
> therefore the location might differ based on variables.
>
> Can I use external variables somehow in .htaccess ?
> E.g. {TARGET_DIRECTORY}/templates/png_help/$1.png


Hi Peter,

If I were you I would repost this in alt.apache.configuration

>
> Or call a function that outputs the directory ?
> e.g. <?php echo DIR ?>/templates/png_help/$1.png


That will surely not work.
You have no PHP variables available in your apache configuration.


>
> or .... ???
>


Maybe you can solve this with a rewriterule, but I don't know how.
Alternatively you can simply call a PHPscript that returns the png.

From HTML, instead of:
<img src="templates/png_help/example.png">

you write:

<img src="mypngscript.php?png=example.png">

And let mypngscript.php handle all complex path stuff.

Regards,
Erwin Moller


Ian Hobson

2008-01-30, 7:10 pm

Erwin Moller wrote:
> Peter wrote:
[color=darkred]
>
> Maybe you can solve this with a rewriterule, but I don't know how.
> Alternatively you can simply call a PHPscript that returns the png.
>
> From HTML, instead of:
> <img src="templates/png_help/example.png">
>
> you write:
>
> <img src="mypngscript.php?png=example.png">
>
> And let mypngscript.php handle all complex path stuff.
>
> Regards,
> Erwin Moller
>
>

If you do this, don't forget to set the headers correctly.

I had to use the following when generating a .pdf (which I did not want
cached).

header('Content-Disposition: inline; filename="'.$this->pdfFilename().'"');
header('Content-type: application/pdf');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header('Expires: '.date(DATE_COOKIE,time()-120));
header('Pragma: public');

You can find the correct value for your content-type line in the
mime.types file in your apache configuration directory.

Regards

Ian
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com