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 8966729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:04:54+00:00 2026-06-15T17:04:54+00:00

I am using a server-side image resizer to automatically serve up images at the

  • 0

I am using a server-side image resizer to automatically serve up images at the correct size.

The image resizer takes its parameters for resizing from the request URL, so I’ve set up some .htaccess rewrite rules to make the URLs for the images a bit prettier:

RewriteRule ^.*photos/homehero/(.*)$ /v2/imgr/w1140-h640-c16x9-q100-p1/v2/photos/$1 [R=301]

Using the above, I can use http://example.com/photos/homehero/file.jpg in my code and it returns a photo at the correct size. This works perfectly as is, and the resizer automatically caches images on the server after they’re generated so the site is reasonably speedy. I have 5 different sized images at the moment.

Taking into account screen-size and bandwidth considerations, I’d like to serve up a separate set of images with the width/height reduced (w1140-h640 above) and the quality reduced too (q100 above) for mobile users.

I’ve added a rewrite condition to detect user agent with a second set of rewrite rules. This is below the original rules, eg:

RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule ^.*photos/homehero/(.*)$ /v2/imgr/w570-h320-c16x9-q50-p1/v2/photos/$1 [R=301]

However this doesn’t seem to work. I have tried putting the second block above the first but that didn’t work either, and I’ve also tried using a not flag for the user agent (%{HTTP_USER_AGENT} "!(android|…) before the “normal” rewrite rule block, but that didn’t work.

I have googled and searched StackOverflow and found similar-but-not questions, so I’m wondering if this can actually be achieved in .htaccess? My full rule block is below, any help would be much appreciated.

#Image Resizer Standard sizes   
RewriteRule ^.*photos/homehero/(.*)$        /v2/imgr/w1140-h640-c16x9-q100-p1/v2/photos/$1 [R=301]
RewriteRule ^.*photos/tile-small/(.*)$      /v2/imgr/w504-h252-c6x3-q100-p1/v2/photos/$1    [R=301]
RewriteRule ^.*photos/hero/(.*)$            /v2/imgr/w1140-h200-c57x10-q100-p1/v2/photos/$1 [R=301]
RewriteRule ^.*photos/productshot/(.*)$     /v2/imgr/w1140-h640-c16x9-q100-p1/v2/photos/$1  [R=301]
RewriteRule ^.*photos/gallerythumb/(.*)$    /v2/imgr/w160-h90-c16x9-q100-p1/v2/photos/$1    [R=301]

# mobile site redirection
RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule ^.*photos/homehero/(.*)$        /v2/imgr/w570-h320-c16x9-q50-p1/v2/photos/$1 [R=301]
RewriteRule ^.*photos/tile-small/(.*)$      /v2/imgr/w504-h252-c6x3-q50-p1/v2/photos/$1 [R=301]
RewriteRule ^.*photos/hero/(.*)$            /v2/imgr/w570-h100-c57x10-q100-p1/v2/photos/$1  [R=301]
RewriteRule ^.*photos/productshot/(.*)$     /v2/imgr/w570-h320-c16x9-q100-p1/v2/photos/$1   [R=301]
RewriteRule ^.*photos/gallerythumb/(.*)$    /v2/imgr/w160-h90-c16x9-q100-p1/v2/photos/$1    [R=301]
  • 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-15T17:04:55+00:00Added an answer on June 15, 2026 at 5:04 pm

    You should put the mobile rules above the desktop rules. Also, you need to repeat the RewriteCond for every RewriteRule.

    So

    # mobile site redirection
    RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
    RewriteRule ^.*photos/homehero/(.*)$        /v2/imgr/w570-h320-c16x9-q50-p1/v2/photos/$1 [R=301]
    RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
    RewriteRule ^.*photos/tile-small/(.*)$      /v2/imgr/w504-h252-c6x3-q50-p1/v2/photos/$1 [R=301]
    RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
    RewriteRule ^.*photos/hero/(.*)$            /v2/imgr/w570-h100-c57x10-q100-p1/v2/photos/$1  [R=301]
    RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
    RewriteRule ^.*photos/productshot/(.*)$     /v2/imgr/w570-h320-c16x9-q100-p1/v2/photos/$1   [R=301]
    RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos)" [NC]
    RewriteRule ^.*photos/gallerythumb/(.*)$    /v2/imgr/w160-h90-c16x9-q100-p1/v2/photos/$1    [R=301]
    
    #Image Resizer Standard sizes   
    RewriteRule ^.*photos/homehero/(.*)$        /v2/imgr/w1140-h640-c16x9-q100-p1/v2/photos/$1 [R=301]
    RewriteRule ^.*photos/tile-small/(.*)$      /v2/imgr/w504-h252-c6x3-q100-p1/v2/photos/$1    [R=301]
    RewriteRule ^.*photos/hero/(.*)$            /v2/imgr/w1140-h200-c57x10-q100-p1/v2/photos/$1 [R=301]
    RewriteRule ^.*photos/productshot/(.*)$     /v2/imgr/w1140-h640-c16x9-q100-p1/v2/photos/$1  [R=301]
    RewriteRule ^.*photos/gallerythumb/(.*)$    /v2/imgr/w160-h90-c16x9-q100-p1/v2/photos/$1    [R=301]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to resize a image using server side script (eg: Smart Image Resizer
I am using DataTables with server-side processing with information from a form. On form
I am using GDI+ on the server-side to create an image which is streamed
I want to crop an image at the server side (I am using 'JCrop'
As we all know, using background-size: cover makes the background-image automatically scale perfectly on
I'm trying to add a server side image uploaded from a user form to
I'm using server side Facebook authentication. So first, the application redirects the client to
How to construct a GQL query using server side admin datastore viewer, a one
I'm using ext.net with asp.net, I'm generating a tree using server side code: Ext.Net.Node
Background: Using jQuery 1.7 client side PHP server side Using json responses with json_encode

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.