English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,
I'm trying to rename a certain file with a .php extension to a .jpg. How would I do this using a .htaccess file? This is what I want the URL to be changed FROM:

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

To this:

http://www.johninteractive.net/photos/13.jpg

How would I do this by using .htaccess file? I tried using another example but I got a HTTP 404 error.

SORRY IF YAHOO! CUTS OFF THE URLs. If this happens, just click on the link to see what I mean. Thanks a lot!

2007-07-06 15:11:32 · 7 answers · asked by John1704 3 in Computers & Internet Programming & Design

I know it's possible. I want it to show as a .jpg image, with php scripts in it, but disguised as a .jpg file. The forum I'm using does not accept .php files for security purposes, so I need to create someway to so that when someone makes a request for a .jpg file, it makes it go to the php file instead. I figured I could do it with a .htaccess file, and apparently, I was right. Using the rewrite rule you can do it, I just didn't know how.

2007-07-07 02:35:54 · update #1

7 answers

You can do this using the mod_rewrite module, but only if it is installed on your server.
If it is in your .htaccess file write this
RewriteEngine On

Then you can write your rewriting rules like this
RewriteRule ORIGINAL_NAME NEW_NAME
eg. RewriteRule image.php image.jpg
These names can use regular expressions so you only need one rule for an entire set of php files.

A reference for regular expressions can be found here
http://www.regular-expressions.info/quickstart.html

2007-07-06 16:29:51 · answer #1 · answered by jonathanlks 4 · 3 0

jonathanlks is correct.. Your question is a bit confusing because you REALLY are NOT renaming the file you are just calling it (still processing with PHP) but shortening the URL.

That is called Mod_rewrite and can be used on most servers as long as mod_rewrite is enabled. The image being displayed within your page is still named .jpg with either of your two links. The differrence is that the first one shows page.php?id=13
and the second one will use an htaccess instruction to shorten that to 13.html (if you want to keep the same page in use!)

Either will still show the same JPG image!

2007-07-07 00:25:30 · answer #2 · answered by Tracy L 7 · 0 1

You have 2 options with Apache that I know of.

1) Add a script alias in the httpd configuration files for apache. (The line below wrapped) I am putting spaces around the /s so yahoo doesn't abbreviate

ScriptAlias /relative/ path/ from/ web/ root/ imagedisplay.jpg /full /path /from /server /root /imagedisplay.php

2) Use a little know way to call a program and pass arguments while making the browser think the full path is real.

To do this, set the link to
http://HOST/ photos/ imagedisplay.php/ id=3/ pict.jpg
or
http://HOST/ photos/ imagedisplay.php/ 3/ pict.jpg
or in your case
http://www.johninteractive.net/ photos/ imagedisplay.php/ id=3/ pict.jpg

Then adjust the imagedisplay.php program to parse out the REQUEST_URI instead of the QUERY_STRING. The parameters would be positional parameters with the / being the delimitter. You can even include named pairs in between the /s such as /id=3/type=jpg/name=info/pict.jpg

The pict.jpg is just to fool the browser or other software requesting the file.

If one of the directories in the full path is a program instead of a directory, it gets executed. This is probably the easier method.

2007-07-10 14:13:54 · answer #3 · answered by Dave H 4 · 0 0

Just renaming the files (which you can do in Windows Explorer or My Computer just as you can with any other file) doesn't change the contents. The files will still be php files inside and won't be viewable with any jpg viewer or editor.

2007-07-06 15:18:04 · answer #4 · answered by The Phlebob 7 · 0 2

You can't just rename the file with a .jpg extension since it was saved as a photoshop file. You should open it with photoshop and then do a save as and choose jpg. It's pretty simple then you can do what you want with it.

2007-07-06 15:21:30 · answer #5 · answered by jason1029 2 · 0 2

there's no would desire to reinvent the wheel - you ought to use a classification (source code provided). i will additionally connect an academic for the easy products to ascertain in case you enforce the upload your self.

2016-09-29 05:54:07 · answer #6 · answered by ? 4 · 0 0

Why not just right click and select rename?
Or if your trying to have them open with a different program right clik and select Open With?

2007-07-06 15:18:21 · answer #7 · answered by DOUGLAS M 6 · 0 2

fedest.com, questions and answers