Forum Moderators: phranque

Message Too Old, No Replies

Rewriterule redirect problem.

Images don't work on redirected page.

         

Afkamm

4:08 am on Jan 29, 2008 (gmt 0)

10+ Year Member



Hi, I have a problem I can't figure out. What I'm trying to do is when people enter a url direct to one of my images, they get redirected to a php script which then displays that image.

http://www.example.com/folder/folder/image.jpg

becomes...

http://www.example.com/script.php?s=folder/folder/image.jpg

Here's my htaccess code.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(gif¦jpe?g?¦png)$ [NC]
RewriteRule ^(.*)$ /gallery.php?s=$1 [R=301,L]

Now this works, but the page appears without any images, not even the ones in the css file.

Any clue as to why that is?

[edited by: jdMorgan at 4:23 am (utc) on Jan. 29, 2008]
[edit reason] example.com [/edit]

jdMorgan

4:23 am on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because you're redirecting *all* HTTP requests for images, including those in CSS, etc.

Also, this shouldn't even be a redirect, since it exposes your script, and removes any 'security' advantage that the script might provide.

The rule (or rules) need to be more selective about URL-paths, and HTTP request phases in order to work.

Can't suggest a solution right now... Maybe someone else will see something that's not obvious to me right now.

Jim

Afkamm

1:37 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Somebody mentioned, removing the file extension and using,

DirectoryIndex index index.php index.html

<Files index>
ForceType application/x-httpd-php
</Files>

..to force the file to be parsed, thus making the url look like,

http://www.domain.com/index/folder/folder/image.jpg

Tried that out and it did work, but again if somebody went direct to the image and I tried to redirect them, none of the images showed up on the page.

I'm sure I've seen this done. :(

jdMorgan

2:29 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As stated above, your URLs need to contain *some* information that can be detected by RewriteRule and RewriteCond patterns to distinguish image URLs that should be redirected from those that should not.

As it stands now, all images on your site will be redirected to your gallery script.

Don't complicate things by trying to use extensionless URLs before you get the basic image rewriting sorted; You will end up with a 'layered' problem, which will be *much* more difficult to fix.

And again, as stated, you'll likely be happier changing these redirects to internal rewrites -- after you get the basic URL issues worked out.

Consider putting your images into two subdirectories; One for image-script gallery images, and the other for images that are part of your pages -- logos, buttons, icons, backgrounds, etc. Then your mod_rewrite rules will be able to tell which image requests need to be routed through your script.

Jim