Forum Moderators: phranque

Message Too Old, No Replies

some help with rewriterule

         

stefanosc

4:58 pm on Aug 21, 2012 (gmt 0)

10+ Year Member



I am trying to rewrite one URL in our Joomla website.
It's a php file we created to force download for some files we store on Amazon S3.

without rewriting the URL currently looks like:

www.example.com/downoald.php?url=https://bucket.s3.amazonaws.com/folder/file.jpg

we would like to rewrite the above to:

www.example.com/download/file.jpg

I am not very familiar in using the mod_rewrite and despite reading quite a few threads on this forum and tutorials online I am unsure how to go about this.
Any help / guidance would be much appreciated.

Thank you!

phranque

10:32 pm on Aug 21, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you want to use a RewriteCond directive to test the query string and extract the file name from the pattern so you can use it as a backreference variable in the RewriteRule.

lucy24

11:11 pm on Aug 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the URL currently looks like:

www.example.com/downoald.php?url=https://bucket.s3.amazonaws.com/folder/file.jpg

we would like to rewrite the above to:

www.example.com/download/file.jpg

Bill, d'you suppose we could make a law against the phrase "rewrite to"? Nobody knows what it means and it just leads to all-around confusion.

:: taking a wild guess ::

The long version is where the content really lives. The short version is what you want people to see and use.

Or is it the other way around?

In your example, is the "file" element the part of the filename name that changes? If you're rewriting, there has to be something for the rewrite to get hold of so it knows where to look. Otherwise you're in php-script territory.

stefanosc

11:18 pm on Aug 21, 2012 (gmt 0)

10+ Year Member



Thank you very much both for your help and sorry for any misunderstanding.

The actual file and working script is located at:
www.example.com/downoald.php?url=https://bucket.s3.amazonaws.com/folder/file.jpg

OR
www.example.com/downoald.php?url=https://bucket.s3.amazonaws.com/another-folder/another-file.jpg

and I would like people to see:
www.example.com/download/file.jpg
OR
www.example.com/download/another-file.jpg
(based on the requested file)

any additional help would be appreciated
Thank you!

phranque

1:47 am on Aug 22, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



ok so you link to the urls you want people to see which if i understand correctly would look like:
www.example.com/download/file.jpg
OR
www.example.com/download/another-file.jpg


now the next question is how do you know whether the amazonaws path is "folder/" or "another-folder/" when all you can see is the requested url (download/file.jpg or download/another-file.jpg)?

stefanosc

1:59 am on Aug 22, 2012 (gmt 0)

10+ Year Member



I thought there was a way to handle this via apache.
But if there is no way to get the folder then we would surely need to display a URL of this kind:

www.example.com/download/folder/file.jpg
OR
www.example.com/download/another-folder/another-file.jpg

Again, thank you so much. On this forum I have always found kindness and generosity in the form of great help.

stefanosc

11:30 pm on Aug 23, 2012 (gmt 0)

10+ Year Member



Could anyone offer some clarifications over the last few posts?
Thank you again

wilderness

11:48 pm on Aug 23, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Could anyone offer some clarifications over the last few posts?
Thank you again


I'll try to assist you in interpretation, however "I'm walking on very thin ice"


OR
www.example.com/downoald.php?url=https://bucket.s3.amazonaws.com/another-folder/another-file.jpg

and I would like people to see:
www.example.com/download/file.jpg
OR
www.example.com/download/another-file.jpg
(based on the requested file)


The long version is where the content really lives. The short version is what you want people to see and use.

Or is it the other way around?

In your example, is the "file" element the part of the filename name that changes? If you're rewriting, there has to be something for the rewrite to get hold of so it knows where to look. Otherwise you're in php-script territory.


lucy was asking you to confirm if the JPG was an ever-changing variable or just a single-JPG?

The end result is likely that your going to need a resolution in PHP, rather than Apache.

stefanosc

2:05 am on Aug 24, 2012 (gmt 0)

10+ Year Member



Thank you so much for your help.
Sorry for not being clear on the question, it's just that I am unsure how to achieve this.

To Answer your question the we have several files so it needs to be "dynamically" changed.
If we have to adjust something in php that's no problem, we are just a bit lost on the apache part..

Thank you so much

phranque

5:05 am on Aug 24, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



But if there is no way to get the folder then we would surely need to display a URL of this kind:

www.example.com/download/folder/file.jpg
OR
www.example.com/download/another-folder/another-file.jpg

yes you are essentially rewriting "download/" to "download.php?url=https://bucket.s3.amazonaws.com/" while capturing the path and file name and appending to the new path.
then make sure download.php issues a proper 404 or 410 response when appropriate.

stefanosc

5:54 am on Aug 24, 2012 (gmt 0)

10+ Year Member



yes that is correct.
I understand that this may well be over my head and don't have the knowledge to set this up.

I would appreciate more help on this but I understand it may be to much to clarify.

Thank you all for your help in so many ways!