Mod_rewrite help

SpaceshipSpaceship
SpaceshipSpaceship
NamecheapNamecheap
Watch

Peter

VIP Member
Impact
209
Hi

I have afdapted a bit of htaccess code very slightly and have come up with the following:-

Code:
RewriteEngine on

RewriteBase /
RewriteCond %{REQUEST_FILENAME} \playing.(gif|jpe?g|png)$ [NC]
RewriteRule (.*) mp3/playing.php [NC,L]

What I am doing is redirecting images to a php script. Can anybody adapt this so that it will work regardless of what directory it is so that it does not have to hard coded.

Cheers in advance
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Well, I'm not sure what you mean but I do see one thing wrong..

jpe?g should be jpeg?
 
0
Close
Dan Friedman said:
Well, I'm not sure what you mean but I do see one thing wrong..

jpe?g should be jpeg?
I think that the question mark is ok there, it allows for jpg and jpeg (the ? allows for the e to disappear).

Im not sure how to do what you wanted though Peter :(, sorry.
 
0
Close
to redirect images to another .php file is to force make all .jpg/.gif/.png images be read by browser as .php files.
.htaccess
Code:
<Files *.png, *.gif, *.jpg>
     ForceType application/x-httpd-php
</Files>

now your .gif/.jpg/.png should contain something like this:
Code:
<?php $URL="http://www.yourotherdomains.com/";
header ("Location: $URL");
exit();
?>
now all images files where the .htaccess above can be found will act as if they're .php

hth
 
Last edited:
0
Close
One thing though, if you redirect ALL image files to a php file, when the php file goes to request that image, wont it simply redirect back to the php file again, looping and looping?
 
0
Close
the .htaccess is only good on the folder/directory where it's saved. when your .php wants to request another image file request it from another path or folder, the said .htaccess must not be stored on /images/ for obvious reasons.
 
0
Close
weblord that is not correct. a htaccess file affects the folder it is in AND all of it's subfolders. So if it is in / then it will also affect /images/. (unless there is a htaccess file that stops the behaviour)
 
0
Close
BillyConnite, yeah your right..

But I'm still not sure what the htaccess is supposed to be doing here.
 
0
Close
0
Close
RewriteRule (.*)?\.(jpe?g|gif|png) $1.php
 
0
Close
thanks dan thats exactly what I needed.
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back