It might work with putting a .htaccess like

RewriteEngine On
RewriteRule ^imagedisplay.jpg$ /imagedisplay.php [QSA]

into the directory photos. I'd actually prefer something like

RewriteEngine On
RewriteRule ^(0-9+).jpg$ /imagedisplay.php?id=$1

That way, a request of http://www.johninteractive.net/photos/13.jpg should be internally redirected to imagedisplay.php3?id=13.

There is another way I found in a similar thread some time ago: Create a directory named imagedisplay.jpg, and put the former imagedisplay.php in there renaming it to index.php. I don't know if arguments will be passed correctly this way though.

    I like your second example better, but I'm getting a 404 error. I think I did something wrong though. I copied and pasted what you had, named it .htaccess and put it in the /photos/ directory. Here are the contents:

    RewriteEngine On
    RewriteRule ^(0-9+).png$ /imagedisplay.php3?id=$1

      Alternatively, you could do:

      AddType application/x-httpd-php .jpg .jpeg
      

        Help!!! Your second example is not working.

          Help!!! Your second example is not working.

          It shouldn't work. That's why it's not working. If you use a re-write rule, then you are changing the name of the file that the web server is looking for - and if you change the name, then that file doesn't exist and you should get a 404 error... which you are, which means that your web server is doing exactly what it should be doing.

          The only solution you have here is what Nog said. You are essentially telling Apache that jpg files should get parsed for PHP content. That has a chance of working. The re-write will not solve this problem for you.

            etully wrote:

            It shouldn't work. That's why it's not working. If you use a re-write rule, then you are changing the name of the file that the web server is looking for - and if you change the name, then that file doesn't exist and you should get a 404 error... which you are, which means that your web server is doing exactly what it should be doing.

            The only solution you have here is what Nog said. You are essentially telling Apache that jpg files should get parsed for PHP content. That has a chance of working. The re-write will not solve this problem for you.

            Then if I used what nog said, what would my URL look like. I have something like this:

            http://www.johninteractive.net/photos/imagedisplay.php?id=14

            and I used Nog's .htaccess file, how would the URL look? Because now I'm getting a stupid internal server error 500. Know what's wrong?

              No... if you use the AddType declaration in the .htaccess or httpd.conf file, you keep the same .jpg extension. What happens is that instead of Apache serving an image file, it rather parses the contents of that file as PHP.

              So your two options are this:

              1.) Have the url look like: /images/myImage.jpg which Apache will use the mod_rewrite extension to revert the .jpg to a .php file for parsing

              2.) Make .jpg and .jpeg files parsed by Apache using the AddType declaration in the httpd.conf or .htaccess file. This way, your URL would look like: /image/myImage.jpg but Apache would process myImage.jpg as a php script.

                bpat1434 wrote:

                No... if you use the AddType declaration in the .htaccess or httpd.conf file, you keep the same .jpg extension. What happens is that instead of Apache serving an image file, it rather parses the contents of that file as PHP.

                So your two options are this:

                1.) Have the url look like: /images/myImage.jpg which Apache will use the mod_rewrite extension to revert the .jpg to a .php file for parsing

                2.) Make .jpg and .jpeg files parsed by Apache using the AddType declaration in the httpd.conf or .htaccess file. This way, your URL would look like: /image/myImage.jpg but Apache would process myImage.jpg as a php script.

                Ok, so I renamed the imagedisplay.php file to imagedisplay.jpg, and saved the .htaccess file with the AddType declaration, but I still get a 500 server error. Do you know why this could be?

                  Personally I'd stick some path info in, e.g.

                  /imagedisplay.php/imagedisplay.jpeg

                  The extra part of the path is available in $_SERVER['PATH_INFO'] for you to use, otherwise you can use a query string as normal. And when the browser saves the file out, it takes the last part of the path (imagedisplay.jpeg)

                  Mark

                    Ok, so I renamed the imagedisplay.php file to imagedisplay.jpg, and saved the .htaccess file with the AddType declaration, but I still get a 500 server error. Do you know why this could be?

                    It's because the hosting company was prepared for people like you who wanted to use this trick. We never said that parsing JPG files for PHP would work... we just said that if anything was going to work, this had the highest likelihood of working.

                    One last thing you might try: rename your PHP file again, give it an extension that you make up (maybe .PXP or maybe .john1704 or something like that) and then change the .htaccess file again with NogDog's command:

                    AddType application/x-httpd-php .john1704 .pxp

                    It might work. If not, I'd consider hosting your web site at one of the $8 per month hosting companies that has PHP.

                      Write a Reply...