954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help in Redirection via htaccess

Hello,
i am running a site consisting mainly of images . the problem im facing is high traffic loads sometimes from social networks on image links directly like : /i/image_123232.jpg instead of the image page.

I have developed teh site in a way to use same image name as teh url of image page.
For examples the image
/i/image_123456.jpg
will have page
/pic/123456

is there a possible redirect im the htaccess that i can redirect the traffic on the images to the image pages instead.

like traffic to : /i/image_12324353.jpg => /pic/12324353
Thx in advance:)

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

This I think:
RewriteRule i/image_(\d+)\.jpg pic/$1 [L]

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Hello,
Thanks alot, i tried it and a little variation but now what happens is. it is redirection the image properly to the right pages but on the page it doesn't show the image. what do u suggest further

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

I don't know what your page does. Perhaps you need the .jpg

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

k let me show u . this is my site www.imgzzz.com . an image hosting. the page displays the image 1 ad etc.
here is a direct image link : http://www.imgzzz.com/i/image_1290297312.jpg
Here is the page link to this image : http://www.imgzzz.com/pic/1290297312

hope that helps. thx

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

Still not quite sure what your problem is. The pic/12 url shows the image and the rest of the page, but the image is still at i/image_12.jpg

If you use my rewriterule, it should not be possible to view _only_ the image in the browser.

Perhaps I misunderstood what you want to achieve.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

K let me explain a bit further.
using your redirect it doesn't show the image o the image page as well.
i want the the direct image access to redirect on image page instead wehre uses can view the image ... inside teh page.
but with this rewrite rule it is redirecting direct access to page but not loading the image inside the page.
i hope that makes sense. right now i disabled your rewriterule

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

Makes sense now. Because the image url is also redirected to this page. You probably need to add something like this:

RewriteCond %{HTTP_REFERER} !^http://(www\.)?imgzzz.com/.*$ [NC]
RewriteRule i/image_(\d+)\.jpg pic/$1 [L]

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Right now its implemented but it doesnt redirect the to image page on directly accessing

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

bravo man bravo worked :D thank u so much ! let me get into it a lil more i will get back to u :)
btw it wil not affect embeding of images outside the site right ?

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

If you try to access the image url, you will be redirected to the page, unless the request is coming from the server itself. Hot-linking directly to the image is now NOT possible.

Btw. the redirect now only works for jpg. If you allow other formats the rule has to be changed.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: