tags:

views:

123

answers:

3

Having trouble rewriting the name of a flash file:

/flash/shell.1257347618.swf (the numbers are a changing timestamp, the idea is to bypass browser caching).

My .htaccess looks like this:

#Use mod.rewrite
RewriteEngine On

#Cache files which are autoversioned
ExpiresActive On
<FilesMatch "\.(swf)$">
    ExpiresDefault "access plus 10 years"
</FilesMatch>

#Remove autoversion timestamp
RewriteRule ^(swf)/(.+)\.([0-9]+)\.(swf)$ $1/$2.$4 [L]

This was passed to me from a third party and it's not matching properly and I'm just no good at regex. Can anyone out there help me out?

The URL I'm testing with is similar to:

http://dev.somedomain.domain.com/flash/shell.1257347618.swf

And I've installed the .htaccess file to the flash directory.

A: 

You use flash/ but the rule assumes swf/, change to:

RewriteRule ^(flash)/(.+)\.([0-9]+)\.(swf)$ $1/$2.$4 [L]
reko_t
That makes sense, but it's still not matching for some reason.
lewsid
A: 

If all files are in the folderName folder and have the extension .swf, you can use the following:

RewriteRule ^folderName/([^.]+)\.\d+\.swf$ folderName/$1.swf [L]

Updated to match different file types in the same folder:

RewriteRule ^folderName/([^.]+)\.\d+\.(\w+)$ folderName/$1.$2 [L]
Amarghosh
Thanks, but unfortunately there are other filetypes in this folder.
lewsid
the example hard coded the type as swf, that's why I used it. updated to match any extension
Amarghosh
A: 

Whatever your folder name and filename the rule:

RewriteRule ^([^/]+)/([^.]+)\.[0-9]+\.swf$ $1/$2.swf [L]

will convert somefolder/file.329873.swf into somefolder/file.swf.

If you need to allow files with subfolders like topfolder/somefolder/file.329873.swf and want to keep all folder hierarchy use:

RewriteRule ^(.+)/([^.]+)\.[0-9]+\.swf$ $1/$2.swf [L]

If you may have names without the numeric part, use

RewriteRule ^([^/]+)/([^.]+)(\.[0-9]+)?\.swf$ $1/$2.swf [L]

Final answer was in the comments. The problem was that the .htaccess was in the same folder as the .swf files so we needed to remove the folder sectio nin the regex like the following:

RewriteRule ^(.+)\.[0-9]+\.swf$ $1.swf [L]
Marcel Gosselin
Thanks, but still no dice.
lewsid
I trust you know what you're talking about, but this still isn't working. Here's some more info, the URL looks like this:http://dev.somesubdomain.somedomain.com/flash/shell.1257347618.swfAnd I've got the .htaccess in the /flash/ directory.
lewsid
I know what I'm talking about when I talk regex but as for .htaccess, there might be some variations on regex syntax. now that i look at your latest comment, maybe we shouldn't try to put the folder in the rewrite rule. Can you try `RewriteRule ^(.+)\.[0-9]+\.swf$ $1.swf [L]`
Marcel Gosselin
Very nice, that seemed to do the trick. You rock.
lewsid