Forum Moderators: phranque

Message Too Old, No Replies

changing 404 images to another image w/ limited server access

         

kristoff

3:04 pm on Sep 13, 2003 (gmt 0)

10+ Year Member



I was looking through a bit on how to change images on our server that do not show up...

now the question I have is a bit more unique... I run a server that has images for users and public viewing... the ones for users are under a password protected directory, and I was looking to see how I could get those when viewed by the public to be replaced with another default image otherwise...

in specific the following page and image (and yes this is for a porn site, so if you can't help, I can understand)

[spookygirls.com...]

should ask for a password, and when you do not have one, it should show this image

[spookygirls.com...]

but I am not sure how to do that...

now the only server issue I have is... I am on a server that I do not have direct physical access too and the root access I have might limit me to what I can do... I have access to the htdocs directory and one level higher... but that would be it...

so how do I fix this without breaking anything?

thanks!
-kristoff

killroy

3:19 pm on Sep 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there, I'm afraid I cannot help you with your problem, I'm sure somebody will be right in with the solution.

In the meantime, please remove the URLs. It's against this boards TOS, and will probably be removed soon anyways.

Thanks,

SN

kristoff

6:12 pm on Sep 13, 2003 (gmt 0)

10+ Year Member



I'll remove em with no worries, but the only thing is I have no way of showing exactly what i would need then...

kristoff

6:14 pm on Sep 13, 2003 (gmt 0)

10+ Year Member



I can't seem to edit the post to remove the URL's either... I know on some UBB's you can but I guess I don't have the access here?

jdMorgan

11:37 pm on Sep 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

Just use "mydomain.com" or "example.com" in your posted URLs, and of course, no offensive words, and it's OK.

You'll need to post more about what capabilities you *do* have to get better help. For example, if you can use mod_rewrite in .htaccess, then there are already a couple of older threads with solutions for detecting and redirecting image requests that would otherwise result in 404-Not Found errors.

Jim

sun818

11:53 pm on Sep 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can check this thread out:
[webmasterworld.com...]

Two solutions:
1) mod_rewrite
2) perl script to serve images (last post)

kristoff

6:11 am on Sep 14, 2003 (gmt 0)

10+ Year Member



I tried using some of the code and I was either using the code incorrect or I do not have the access to do so...

I will ask about the re-write commands however

thanks...

kristoff

3:44 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



I do have access to use the rewrite options and had looked at 2 other threads with this kind of question...

so what would I do to make an 404 image come up with the desired image of

[server.com...]

they had said we start with this coding:
Options +FollowSymLinks
RewriteEngine on

and where would i put this file? in the /htdocs or the directory above is as that is the only root directory access that I have...

jdMorgan

8:15 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

The code is provided in the thread that sun818 quoted above.

Put it in a file named .htaccess in your htdocs directory, if that is where your home page is. You can put it in any directory above the directory where you keep your images, or in your image directory itself.

Jim

kristoff

9:01 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



I tried this code in the /htdocs/.htaccess from the pre-mentioned thread

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI}!-U
RewriteRule ^catalog_image_path/.*\.jpg$ /nonmember.jpg [L]

and that is the only thing in the .htaccess file, should there be something else?

but I got this error on the whole /htdocs directory:

The server encountered an unrecoverable error. This is usually caused by a faulty, or improperly installed CGI script or .htaccess file. If the script is written in Perl, you may wish to use this utility to check for syntax and configuration errors.

any luck?

jdMorgan

12:14 am on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

As long as you have a space preceding the "!" in this line:


RewriteCond %{REQUEST_URI}!-U

your code is complete and correct.

If possible, examine your raw error log file, and see if it gives any indication of the problem. Otherwise, you may not have priveledges to use mod_rewrite after all.

You could also try a simple "test" rewrite, like


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^madeupname\.html$ /index.html [L]

Try it with and without the first directive (the Options line). If both versions cause a server error, then it's pretty certain you can't use mod_rewrite. Contact your host.

Jim

kristoff

12:25 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



the space was the problem...

the server now accepts the script... but I still cant get the graphic to come up...

^catalog_image_path/.*\.jpg$ /nonmember.jpg [L]

where would the image path be and where would the /nonmember.jpg be found? I have it in /htdocs/ but that's it...

also should I chmod it?

thanks again!

jdMorgan

1:36 pm on Sep 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

> but I still cant get the graphic to come up

Meaning what? - Do you get a broken image placeholder, or do you still see the original image?

Assuming that /htdocs is your web root directory (where your "home page" resides), the full expansion of the rewrite target URL for the image using the code above would be

http://www.yoursite.com/nonmember.jpg
and the images it replaces would be in
http://www.yoursite.com/catalog_image_path/<whatever>.jpg

If you are still seeing the original images, you should flush your browser cache (delete your Temporary Internet Files). You will need to do this every time you want to test the rewrite from any machine that you've recently used to look at your site, because the original images will be cached on them, and so they will not be fetched from your server. If the images are not fetched from your server, then the rewrite can have no effect.

You may want to look into controlling the cacheability [mnot.net] of your images. Otherwise, as long as those images are cached on a given PC, they can be re-viewed whether the user is logged-in or not.

Assuming that the replacement image has the same read attributes as the original images, you shouldn't need to chmod anything.

Jim

kristoff

2:42 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



I still get a broken place holder...

but what I am trying to view are images only under
[mysite.com...]
(which is a password protected members only directory)

so I'm trying to get any image under that directory to be replaced with
[mysite.com...]
for anyone else that is not a member as a broken image is in it's place if you do not have a password...

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI}!-U
RewriteRule ^catalog/.*\.jpg$ /nonmember.jpg [L]

so in using that code which the server accepts (it might not read it correct, however)

what would be the proper syntaxt to direct to that directory?

jdMorgan

2:59 pm on Sep 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

Your code is correct, assuming that you still have the space before the "!".

However, it may need to be adjusted depending on where your .htaccess file resides. The code you posted would go in your web root ("home page") directory.

If you are still having trouble, you might want to try a very simple rewrite, such as


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.jpg$ /nonmember.jpg [L]

Request [yoursite.com...] , and you should see nonmember.jpg

Also, take a look at your raw error log. It often will give you a hint as to what is wrong. It is possible you may need to use the RewriteBase [httpd.apache.org] directive to get things working.

Jim

kristoff

3:39 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



the simple test worked fine... so I'll dig deeper to see what I can do...

thanks again!

kristoff

3:58 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



hrmmm well that seemed to not work as planned...

if the member has access and the image is 404 then the image shows up...

but if the member does not have access then the image is still broken... so I assume at this point then I'm looking to change broken 401 images instead?

xxx.xxx.xxx.xxx - - [17/Sep/2003:00:08:20 -0700] "GET /catalog/image.jpg HTTP/1.1" 401 231 "http://www.mysite.com/home.php?cat=52" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"

is what shows up in my log...

jdMorgan

4:30 pm on Sep 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kristoff,

The code you have so far does not comprehend user authorization. In addition, .htaccess is processed after the authorization phase, so it's not much use for custom-handling of the authorization aspect. All the code does is to serve a default image if a requested image does not exist. If that image is in your web root directory, then authorization is not taken into account.

What might be worth thinking about is this: .htaccess in a lower-level directory can override .htaccess in its parent directory. You may be able to use this to have different behaviours depending on whether the user is in a authorized directory or not.

For example, by moving the replacement image to the protected directory, then authorized users would see the replacement if they requested a non-existent image. Unauthorized users would get the password-required page. Just remember that the authorization to access files is associated with the directories and subdirectories those files reside in.

You may need to move all of this handling into your scripts in order to get it all to play nice together - the authorization-handling of the server itself is pretty primitive and inflexible. I'll think about this some today while I'm out, and post if I have any bright ideas.

Jim

kristoff

6:41 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



I had tried two configurations...

I placed the .htaccess modifications in these 2 directories...

www.mysite.com
www.mysite.com/catalog

now the test.jpg image was brought up in the main directory... but the catalog directory has the password protection and after prompting for the password and incorrectly answering it, the image comes up broken... but the image comes up correct if you have the correct authentication...

so the broken image upon incorrect authorization is what I'm looking for...