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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:01:49+00:00 2026-05-23T03:01:49+00:00

Using Apache and mod_rewrite I can rewrite a complex request to a simple filename,

  • 0

Using Apache and mod_rewrite I can rewrite a complex request to a simple filename, eg:

RewriteRule ^shortcut/(.*)$ /long/way/around/$1

Can this work in reverse? I want a simple request to be rewritten to an unknown file, but I can identify which file should be served by a unique ID number prefixed to it’s filename. I want Apache to “guess” using a regular expression which file to serve based on the ID.

For example:

GET /img/29281.jpg

Directory of /img/:
...
29280-filename-here.jpg
29281-other-filename-here.jpg  <-- Apache should serve this one
29282-more-files-here.jpg
...

So, a regular expression rewrite could perhaps be:

^(\d+)\.jpg$   -->   ^$1\-[a-zA-Z0-9-_]+.jpg$

How to integrate this into Apache (if it’s possible)?

Many thanks for any suggestions.

P.S. Renaming all the filenames to the simple ID number isn’t an option in this instance.

  • 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-05-23T03:01:49+00:00Added an answer on May 23, 2026 at 3:01 am

    I think one of the apache-way is to use mod-rewrite with the RewriteMap directive, and using the :prg mapping of the rewritemap.

    This will load at apache start a simple program (may be a perl one as suggested in documentation, a PHP program may get more memleaks & performance problems, IMHO). This program will have to do the last part of the filename guess.

    You can find some examples of such programs here (PHP), there (C), and here a Perl basic one.

    I’m not enough perl-enabled in my brain to get the perl way of extracting real filename taking the extension and the int identifier but that should be easy and short (which is important for a PRG rewriteMap).

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

Sidebar

Related Questions

I have an existing site in php running on Apache using the mod_rewrite plug-in.
Using Apache's commons-httpclient for Java, what's the best way to add query parameters to
I'm using Apache's mod_rewrite to route requests for JPG files to a directory outside
I am using Apache 2.2 and mod_rewrite. I would like to take the following
I am trying to run CherryPy behind Apache using mod_rewrite, as described in the
How can I get anything but files to rewrite to index.php's params? I'm using
My company develop web apps using combination of mod_perl, axkit and apache. We have
I am using Apache Axis to connect my Java app to a web server.
I am using Apache HttpClient and would like to communicate HTTP errors (400 Bad
I'm using Apache Subversion to manage and store a decent volume of code. Trying

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.