Community Support Forums — WordPress® ( Users Helping Users ) — 2012-01-19T14:52:41-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=14643 2012-01-19T14:52:41-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=61011#p61011 <![CDATA[Re: Relative links in download restricted documents?]]> See: viewtopic.php?f=4&t=16886&p=61010#p61010

Statistics: Posted by Jason Caldwell — January 19th, 2012, 2:52 pm


]]>
2011-08-29T10:37:39-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=33233#p33233 <![CDATA[Re: Relative links in download restricted documents?]]>

Statistics: Posted by dhempy — August 29th, 2011, 10:37 am


]]>
2011-08-27T15:54:34-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=33102#p33102 <![CDATA[Re: Relative links in download restricted documents?]]> Statistics: Posted by Jason Caldwell — August 27th, 2011, 3:54 pm


]]>
2011-08-26T21:48:24-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32981#p32981 <![CDATA[Re: Relative links in download restricted documents?]]>

Statistics: Posted by Cristián Lávaque — August 26th, 2011, 9:48 pm


]]>
2011-08-25T15:14:21-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32894#p32894 <![CDATA[Re: Relative links in download restricted documents?]]>

This basic rule got me the needed functionality, quite gracefully:

Code:
RewriteRule ^lab_files/(.*)$ index.php?s2member_file_download=$1 [L] 


That converts this:
Code:
http://example.com/lab_files/lab.swf

...to this:
Code:
http://example.com/index.php?s2member_file_download=lab.swf


I added this to my root .htaccess file. I think you could put it in httpd.conf or s2member-files/.htaccess if it suited you. I then tweaked it a bit further to use the default virtual directories in our WordPress permalinks a bit more gracefully, and to only match Flash .swf files:

Code:
RewriteRule ^apparatus/(.+\.swf)$ bogus_path/?s2member_file_download=$1 [L] 


This supports subfolders, so post slugs under custom post types work seamlessly, allowing differrent posts to use different files with the same name with no conflicts. (e.g. lab.swf in several different labs.) The "bogus_path" folder can be any path that does not exist and is not used on the site. No one ever sees that path.

This makes the following transformations:
Code:
http://example.com/apparatus/force-table/lab.swf   becomes:
http://example.com/bogus_path?s2member_file_download=force_table/lab.swf

http://example.com/apparatus/gravity/lab.swf   becomes:
http://example.com/bogus_path?s2member_file_download=gravity/lab.swf


Most importantly, when lab.swf refers to src=beaker.swf (with no path/query information), it makes this request of the server:

Code:
http://example.com/apparatus/force-table/beaker.swf


...which works perfectly. This is great for our site, where the will only be a dozen posts using this technique, without frequent updates. If this was seeing dozens of posts per day, using subfolders for each might be a bit annoying to maintain. Maybe better to have a naming convention that allows all files to be in one folder without fear of conflicts.

THANK YOU, JASON! You just got yourself a paying customer!

-dave


ps. I'm sure you recommend the following elsewhere, but I hadn't noticed it until now. FWIW, I created an .htaccess file in the s2member-files folder with one line:

Code:
deny from all


This prevents someone from gaining some insight into our use of s2member (unlikely) and downloading the file directly, bypassing WordPress and s2member entirely.

And in the spirit of belts-n-suspenders paranoia, I added the following to httpd.conf, which duplicates the "deny from all" in the folder's .htaccess file:

Code:
   <Directory /var/www/example.com/wp-content/plugins/s2member-files/   >
      Options -Indexes FollowSymLinks MultiViews
      Order allow,deny
      deny from all
   </Directory>


Cheers,
-dave

Statistics: Posted by dhempy — August 25th, 2011, 3:14 pm


]]>
2011-08-24T09:37:10-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32789#p32789 <![CDATA[Re: Relative links in download restricted documents?]]>
I had some success with <base href...> but had other issues.

Thanks, Jason!

-dave

Statistics: Posted by dhempy — August 24th, 2011, 9:37 am


]]>
2011-08-23T19:38:34-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32717#p32717 <![CDATA[Re: Relative links in download restricted documents?]]> Thanks for the heads up on this thread Cristián.
~ and thanks for the excellent question.

Well, in HTML, I've seen site owners use a BASE HREF tag like this:
Code:
<head>
<base href="http://example.com/?s2member_file_download=" />
</head>

In Flash though, that would not work. You could try mod_rewrite with a virtual directory. That way all requests for http://example.com/virtual-directory/file.swf would be re-written with mod_rewrite for Apache, by converting them to: http://example.com/?s2member_file_download=file.swf.

Either that, or you may need to pass a BASE HREF value into your Flash file using FlashVars, and then use that inside your ActionScript to reformulate all relative locations into full URLs.

I hope that helps :) Thanks for the KUDOS!!

Statistics: Posted by Jason Caldwell — August 23rd, 2011, 7:38 pm


]]>
2011-08-23T02:10:07-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32670#p32670 <![CDATA[Re: Relative links in download restricted documents?]]>

I'm emailing Jason so he helps you with this.

Statistics: Posted by Cristián Lávaque — August 23rd, 2011, 2:10 am


]]>
2011-08-22T17:22:02-05:00 http://www.primothemes.com/forums/viewtopic.php?t=14643&p=32626#p32626 <![CDATA[Relative links in download restricted documents?]]>
I've got a file I'm restricting with s2member's File Download Restrictions. The file in question is a Flash animation (lab.swf), but this question would apply to a protected .html file as well. This Flash file references another flash file (beaker.swf). Before we attempted to restrict access to the file, the container animation used a relative reference to the second animation, assuming it is in the same directory. So, lab.swf has the Flash equivalent of <img src="beaker.swf" /> in it.

Now that our link to the container file uses a query string
(e.g. http://example.com/?s2member_file_download=lab.swf ) , relative links lose the query string. The second file's HTTP request ends up like this:
(e.g. http://example.com/beaker.swf )

This file, of course, does not exist, and s2member never gets a change to process the s2member_file_download parameter.

We have the option of recompiling all our .swf files with hard-coded links including the query string, but this does not work when we deploy these files in other ways.

Is there a way to use relative links in a download-protected document? Perhaps use a virtual directory instead of a query string to link to the container file? Some other clever hack I'm overlooking?

FWIW, I'm new to s2member, fairly new to WordPress, and a 20-year web programmer veteran.

-dave

ps. I'm still evaluating s2member vs. other plugins for this project, and so far YOU GUYS ROCK!!!

Statistics: Posted by dhempy — August 22nd, 2011, 5:22 pm


]]>