homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Mod rewrite, ignore escaped characters for directory

Msg#: 4639825 posted 10:03 am on Jan 24, 2014 (gmt 0)


I've created a caching function which caches images and then uses urlencode() (PHP) on them and put them in 1 cache directory, and thus a cached image file name can look like this: 400%2F0%2Ffiles%2Fimage.jpg but my htaccess thinks the %2F are slashes and returns a 404 because of it.

What I'd like is for the htaccess to ignore escaped characters in the specific folder 'cache/' =P

I've exhausted all of my ideas, can anyone help? :)

Here's my current htaccess:

Options -indexes

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)$ %{REQUEST_URI} [R=404,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ index.php/$1 [L,QSA]

RewriteCond %{REQUEST_URI} ^/core/.*
RewriteRule (.*)$ index.php/$1 [L,QSA]

-- Thareh



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4639825 posted 10:24 pm on Jan 24, 2014 (gmt 0)

:: detour to Apache docs followed by prolonged experimentation in test site ::

It can be done, but it's so convoluted and peril-fraught that I honestly think you're better off with a simple, conditionless

RewriteRule ^cache/(.+) /fixup.php?path=$1 [L]

and let the php do the converting. The alternative is to make a series of RewriteRules-- as many as your directory structure is deep-- on this pattern:

RewriteRule ^cache/([^/]+)/([^/]+)$ /cache/$1%%22F$2 [L,NE]

Did you get the %%22? You have to do this because "%2" alone is interpreted as "the second capture from the most recently met condition" even if there never was a condition. And then you need the NE flag to keep it from turning into something with %25 in the middle representing a literal percent sign.

A final quirk is that when I did this experimentally, I ended up with a double-404: first the expected 404 because I was redirecting to nonexistent pages, and then a further error message that said it couldn't find the 404 page. I suspect this is because the [NE] flag remains in effect somehow, so the server is looking for "boilerplate%2Fthe404page.html". (The last bit is only a guess. I'd have to do some further experimenting in MAMP with a RewriteLog to make sure.)

Well. That was interesting :)


Msg#: 4639825 posted 7:21 am on Jan 27, 2014 (gmt 0)


Thank you very much for your experiment, very nice of you to try and solve this annoying dilemma =P

Seems the best way to go is to use PHP or just replace all the forward slash characters with something else that apache doesn't convert automatically then =P

Thanks again,
-- Thareh

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved