-1

I just revisited this question from 7 years ago because someone had very fairly downvoted because even I don't remember what I was asking originally; but I'll try to turn this into a real question.

It looks like what I was asking was that if I visited a particular link, for example,
mydomain.com/sheet.csv?z=abcdefg,
then what it does is save the part of the query string, abcdefg, into a csv file.

Then if I manually visit another URL such as:
mydomain.com/sheet.csv?z=hijklmn,
then it appends hijklmn to the next line of the csv file.

If that's what I was asking originally, since 7 years ago I have an idea about how to do this. Essentially I think I would just save it to a file in the same way as a text file, just named as a csv.

Then with each visit of a new link with a new query string on it, it would just get the URL that it came from using javascript, get the query string from the URL (possibly anything after the ? or perhaps there's a query string function in javascript), and then just create a new line on the text file named as a .csv file and then append that new query string into a new row in the file.

Do you think this would work, or would you suggest a different method?

  • It's not really clear what you want to do, and you don't mention anything about your server-side environment: whatever you do you will need to do some kind of configuration or coding there. E.g see http://stackoverflow.com/questions/19850052/rewrite-htaccess-for-clean-url-and-custom-404-page – Tim Williams Dec 18 '14 at 00:55
  • Are you maybe looking for `http rewrite`? http://httpd.apache.org/docs/2.0/misc/rewriteguide.html – Mark Setchell Dec 18 '14 at 00:56
  • This is a question of your web server software. What does it want to do with the query string? Chances are it is not making CSV files accessible. It is more likely _generating_ the file when you request it. – John Saunders Dec 18 '14 at 01:02
  • It was a badly worded question from 7 years ago without enough details. My apologies. I just updated it with what I think I was asking back then. – programmingaddict May 24 '21 at 19:02

2 Answers2

1

The query string parameters, by themselves, do not do anything. They are simply name/value pairs that can be parsed and used by the endpoint you are attempting to request (http verb GET).

So unless your sheet.csv is actually a program, or an obscure API endpoint, it will not be able to redirect the user to a different url. To do this, you need to use a rewrite module or other server side program to capture the information from the querystring, build the new url, and redirect the user's browser.

As Mark Setchell mentioned in a comment above, information on the apache rewrite module can be found at: httpd.apache.org/docs/2.0/misc/rewriteguide.html

If this is used, the rule would be

RewriteRule ^sheet.csv?z=([_0-9a-z-]+) /$1/sheet.csv [R] 
Phil Cazella
  • 854
  • 5
  • 11
  • It returns a 404 error when I tried this. The information you gave was helpful so I voted up, but the htaccess code you gave is not working. – programmingaddict Dec 18 '14 at 01:39
  • Also I double-checked and if I go directly to `mydomain.com/abcdefg/sheet.csv` it exists, but if I go to `mydomain.com/sheet.csv?z=abcdefg`, then it returns a 404 error. – programmingaddict Dec 18 '14 at 01:43
  • Verify that the rewrite_mod is enabled http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2 – Phil Cazella Dec 18 '14 at 13:42
0

If you are using IIS7+ there is a URL rewrite module that can be configured to change the incoming url string to match the pattern you are attempting to redirect to.

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

Basically, you tell IIS to watch for the pattern "^sheet.csv?z=([_0-9a-z-]+)"

and if found, bounce the user to "{R:1}/sheet.csv" instead

The {R:1} part is a dynamic variable defined by the parenthesis of the pattern regex.

The rewrite rule would therefore look like this in your web.config file.

<rewrite>
  <rules>
    <rule name="Rewrite for sheet.cvs">
      <match url="^sheet.csv?z=([_0-9a-z-]+)" />
      <action type="Rewrite" url="{R:1}/sheet.csv" />
   </rule>
  </rules>
</rewrite>
Phil Cazella
  • 854
  • 5
  • 11