regexapachemod-rewriteurl-rewriting

Lowercasing only the file extension in a requested URL


The Issue

I believe I need to rewrite only the file extension of PDF files requested by end users to be lowercase, but don't want to lowercase the entire URL.

Background

I have a web application which includes links to a few PDF files. These files have names in mixed case, but the file extensions are lowercase (Bobs_Your_Mom.pdf).

An older version of this application was just static web content. In that version, the files had uppercase file extensions (Bobs_Your_Mom.PDF)

For the sake of this example, I have no access to change the names of the PDF files, or to force all URLs in the application to be lowercase.

In front of this application is an Apache webserver acting as a ReverseProxy. Traffic coming in on :80 gets redirected to :443 and the proxy redirects the traffic through the internal firewall to the backend server, etc etc.

Presently, there is no manipulation of the URL requested by the end user via their web browser. However, though the old 'site' and new 'application' are obviously different from a technical perspective… roughly two months after the switch I am still getting requests for the relevant PDF files with uppercase file extensions (.PDF).

The web application actually doesn't expose the PDF files directly the way the old site did and the user has to take some special action to even make that request now.

I had been hoping this issue would settle as 404 errors received would alert people to changes having been made, etc. But it has not, and I continue to receive 404's for the uppercase file names even as of a few minutes ago.

Tried

Check Code for Errors

I have validated with the developers and manually myself that no reference exists to PDF files in all caps in the application. This is actually how I discovered the old site did have it this way.

Ask Devs to Change App / Lowercase Entire URI / Business to Change File Names

Developers have indicated no ability/time to alter the application to force all URIs lowercase within the application itself, and the business has indicated the client doesn't want us to actually alter the file names in any way.

301/302 Redirects

This change isn't really for SEO, the old file names redirecting to the new file names would be ok if I knew the 404s were coming from the same set of users with bookmarks (the old site was live for two months before switching to the web app). But requests are coming from entirely new users in entirely different geographic regions, and I cannot make sense of how so many random users would have a bookmark to a URL which existed for only two months without much publicity.

Duplicate Issue / Check Other Posts

From what I have seen other have required help rewriting whole URIs or part of URIs which aren't the file extension, or simply to hide the extension altogether.

I am not sufficiently skilled with regex to figure this one out on my own (regex is a life struggle for me). I can't really make heads or tails of the expressions in the other posts which makes understanding what I change and why as confusing for me as regex looks to my grandmother.

Your Help

However, With dozens of what I believe to be unnecessarily negative user experiences each day, I am hoping mod-rewrite and Apache can come to my rescue. (ALERT: I am regex illiterate).

Normally on the stacks I like to ask just to be pointed in the right direction. I believe users (including myself) should be able to piece things together and get things working with only some guidance.

In this case, I have no-one around me sufficiently talented with regular expressions to assist in this quest of mine to simply convert .PDF to .pdf whenever requested in-flight.

If I can get help to convert:

Im_An_Example.PDF

To:

Im_An_Example.pdf

You will be my savior this day and win 25 whole internets.

Final Solution

The final solution, suggested by @signal2013 is as follows:

RewriteEngine on
RewriteRule ^(.*).PDF$ http://exmple.com/$1.pdf [R=301,L]

The solution is simple, and I acknowledge I was making it much more complex in my mind when trying to solve this on my own.


Solution

  • Yep, like @marekful said, your question is a bit too long. Are you looking for something like this... can go in a .htaccess file.

    RewriteEngine on
    RewriteRule ^(.*).PDF$ http://exmple.com/$1.pdf [R=301,L]