Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7740929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:54:03+00:00 2026-06-01T08:54:03+00:00

I would like to redirect all images to a showimage.php, using htaccess But if

  • 0

I would like to redirect all images to a showimage.php, using htaccess

But if I try something like

RewriteRule ^images/([A-Za-z1-9]+).png$ showimage.php?image=$1 [L]

the image to be shown on that page will get redirected too (doh)

How to redirect all images, but not if they are requested from showimage.php? (or from this server)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:54:04+00:00Added an answer on June 1, 2026 at 8:54 am

    There are two things you can do:

    1- no redirect if the query comes from the server
    You just have to add a RewriteCond directive before the RewriteRule, which says that the following RewriteRule is not to be done if the source of the http query is this server.

    RewriteCond %{REMOTE_ADDR} !127.0.0.1
    

    Depending on how your script does the get, you may need to use instead your server’s private IP. Or add another RewriteCond with this IP, to prevent both to be redirected.

    2- you can also prevent redirect depending on the referer of the query, but you have to be sure that it is sent with the query. (referer is the source URL that requested your URL. For example, if you’re on http://localhost/index.php and click a link to http://localhost/help.php, the referer of the last one will be http://localhost/index.php).
    You still use a RewriteCond, but with HTTP_REFERER instead of REMOTEHOST.

    eg:

    RewriteCond %{HTTP_REFERER} !showimage.php

    RewriteCond %{HTTP_REFERER} !/images/.*\.png
    

    You may have to toy a bit with the full referer, not user if this is enough, but just the idea to start with.
    You can check which referer you have in the access log (if you have %{Referer}i enabled in the LogFormat you use)

    Got it : problem was that, the REFERER is the URL that was asked, and not the rewritten one (should I’ve thought about it, it’s obvious). So, the problem is that when you require http://localhost/images/x.png, it is rewritten as http://localhost/showimage.php?image=x.png which serves the page with the inside. BUT the referer is NOT showimage.php but …/images/x.png (the initial URL). So, the RewriteCond on the HTTP_REFERER must check that the origin URL is something like /images/*.png instead.

    Here is my working example. Rules are in [DOCROOT]/.htaccess file:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !/images/.*\.png
    RewriteRule ^images/([A-Za-z1-9-]+).png$ image.php?name=$1 [L]
    

    Here is my image.php file:

    <html>
    Here it is : <img src="/images/<?php echo $_GET['name']; ?>.png"/>
    </html>
    

    With my browser, calling http://[server ip]/images/foo.png will display an html page, containing the words “Here it is : ” AND the requested picture, taken from [DOCROOT]/images/foo.png.

    For the “not from this server” to work, you just add the previous RewriteCond about REMOTE_ADDR before the RewriteRule (when you don’t specify [OR], they work as AND conditions – the rewriterule is triggered only if both conditions are true – not from this server and not from the php script)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

htaccess redirection and would like to redirect all visitors on (domain.com, domain.com/,domain.com/index.php ) to
I have a main page, index.php and I would like to redirect all URI
I am using Ruby on Rails 3 and I would like to redirect all
I would like to redirect as such... http://old.com/a/b/ -> http://new.com/y/z/ http://old.com/a/b/file.php -> http://new.com/y/z/ http://old.com/a/b/c/file.php
I have this scenario where I would like to redirect my domains using the
I am developing php application with cURL library. I would like to get redirect
I would like to redirect all www traffic to non-www traffic I have copied
I read about freopen to redirect all printf to a file, but I would
I would like to redirect all urls from the webpage (what ever what's after
I would like to redirect all requests to a subfolder on down on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.